Skip to content
This repository was archived by the owner on Nov 16, 2024. It is now read-only.

Commit 59309f4

Browse files
Backward compat for Unity 2018 .NET backend (#218)
* Remove unused using that Unity added. * Bump patch version to v1.5.4. * Modify StreamWriter usage to be backward compatible to deprecated .NET backend (Unity 2018). * Prep packaging files for v1.5.4. * Fix case where sometimes ASA anchors fail because they aren't ready, by adding delay by 1 frame between create and access. * Missing paren.
1 parent bb3215f commit 59309f4

13 files changed

Lines changed: 83 additions & 37 deletions

File tree

Assets/WorldLocking.ASA/Scripts/PublisherASA.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ private async Task<AnchorRecord> RecordFromCloud(AnchorRecord record)
13411341
{
13421342
Debug.Assert(record.cloudAnchor != null, $"Trying to create native resources from a null cloud anchor");
13431343
var wltMgr = WorldLockingManager.GetInstance();
1344+
await Task.Yield();
13441345
#if UNITY_WSA
13451346
Pose spongyPose = record.cloudAnchor.GetPose();
13461347
var lockedPose = wltMgr.LockedFromSpongy.Multiply(spongyPose);

Assets/WorldLocking.ASA/Scripts/SpacePinBinderFile.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ private bool Save(IBinder binder)
6666
return false;
6767
}
6868
var bindings = binder.GetBindings();
69-
using (StreamWriter writer = new StreamWriter(GetFullPath()))
69+
using (FileStream fileStream = new FileStream(GetFullPath(), FileMode.Create))
7070
{
71-
writer.WriteLine($"{binderKey}{binder.Name}");
72-
foreach (var binding in bindings)
71+
using (StreamWriter writer = new StreamWriter(fileStream))
7372
{
74-
writer.WriteLine($"{binding.spacePinId}, {binding.cloudAnchorId}");
73+
writer.WriteLine($"{binderKey}{binder.Name}");
74+
foreach (var binding in bindings)
75+
{
76+
writer.WriteLine($"{binding.spacePinId}, {binding.cloudAnchorId}");
77+
}
7578
}
7679
}
7780
return true;
@@ -95,25 +98,28 @@ private bool Load(IBinder binder)
9598
Debug.LogError($"{name} can't find file {fullPath}");
9699
return false;
97100
}
98-
using (StreamReader reader = new StreamReader(GetFullPath()))
101+
using (FileStream fileStream = new FileStream(GetFullPath(), FileMode.Open, FileAccess.Read))
99102
{
100-
string line = reader.ReadLine();
101-
while (line != null)
103+
using (StreamReader reader = new StreamReader(fileStream))
102104
{
103-
string binderName = line.Replace(binderKey, "");
104-
bool isCorrectBinder = binderName == binder.Name;
105-
Tools.SimpleConsole.AddLine(8, $"Got:{binderName}, Want:{binder.Name}, Math={isCorrectBinder}");
106-
char[] separators = new char[] { ' ', ',' };
107-
while ((line = reader.ReadLine()) != null)
105+
string line = reader.ReadLine();
106+
while (line != null)
108107
{
109-
if (line.StartsWith(binderKey))
110-
{
111-
break;
112-
}
113-
if (isCorrectBinder)
108+
string binderName = line.Replace(binderKey, "");
109+
bool isCorrectBinder = binderName == binder.Name;
110+
Tools.SimpleConsole.AddLine(8, $"Got:{binderName}, Want:{binder.Name}, Math={isCorrectBinder}");
111+
char[] separators = new char[] { ' ', ',' };
112+
while ((line = reader.ReadLine()) != null)
114113
{
115-
string[] tokens = line.Split(separators, System.StringSplitOptions.RemoveEmptyEntries);
116-
binder.CreateBinding(tokens[0], tokens[1]);
114+
if (line.StartsWith(binderKey))
115+
{
116+
break;
117+
}
118+
if (isCorrectBinder)
119+
{
120+
string[] tokens = line.Split(separators, System.StringSplitOptions.RemoveEmptyEntries);
121+
binder.CreateBinding(tokens[0], tokens[1]);
122+
}
117123
}
118124
}
119125
}

Assets/WorldLocking.Core/Scripts/OrienterThreeBody.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections;
66
using System.Collections.Generic;
7-
using System.Configuration;
87
using UnityEngine;
98

109

Assets/WorldLocking.Core/Scripts/WorldLockingManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class WorldLockingManager
3535
/// allowing quick visual verification of the version of World Locking Tools for Unity currently installed.
3636
/// It has no effect in code, but serves only as a label.
3737
/// </summary>
38-
public static string Version => "1.5.3";
38+
public static string Version => "1.5.4";
3939

4040
/// <summary>
4141
/// The configuration settings may only be set as a block.

Assets/WorldLocking.Tools/Scripts/SimpleConsole.cs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,60 @@ public static int AddLine(int level, string line)
116116
}
117117

118118
/// <summary>
119-
/// Cache the instance.
119+
/// Cache this as the instance and open log writer.
120+
/// </summary>
121+
private void Awake()
122+
{
123+
SetupInstance(this);
124+
}
125+
126+
/// <summary>
127+
/// Cache this as the instance and open log writer.
120128
/// </summary>
121129
private void Start()
122130
{
123-
Debug.Assert(_consoleInstance == null, "More than one Status component in the scene?");
124-
_consoleInstance = this;
125-
OpenLogWriter();
131+
SetupInstance(this);
126132
}
127133

128-
private void OpenLogWriter()
134+
/// <summary>
135+
/// Cache the provided instance and open log writer.
136+
/// </summary>
137+
/// <param name="simpleConsole"></param>
138+
private static void SetupInstance(SimpleConsole simpleConsole)
139+
{
140+
if (_consoleInstance != simpleConsole)
141+
{
142+
if (_consoleInstance != null)
143+
{
144+
Debug.LogWarning($"More than one SimpleConsole in the scene? {simpleConsole.name} overriding {_consoleInstance.name}");
145+
_consoleInstance.CloseLogWriter();
146+
}
147+
_consoleInstance = simpleConsole;
148+
if (_consoleInstance != null)
149+
{
150+
_consoleInstance.OpenLogWriter();
151+
}
152+
}
153+
}
154+
155+
private void CloseLogWriter()
129156
{
130157
if (logWriter != null)
131158
{
132-
logWriter.Close();
159+
logWriter.Dispose();
133160
logWriter = null;
134161
}
162+
}
163+
164+
private void OpenLogWriter()
165+
{
166+
CloseLogWriter();
135167
if (!string.IsNullOrEmpty(LogFile))
136168
{
137169
string path = Application.persistentDataPath;
138170
path = Path.Combine(path, LogFile);
139171

140-
logWriter = new StreamWriter(path);
172+
logWriter = new StreamWriter(new FileStream(path, FileMode.Create));
141173
}
142174
}
143175

UPM/asa_files/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[See release notes](https://github.com/microsoft/MixedReality-WorldLockingTools-Unity/releases)
44

5+
## 1.5.4 - Fix timing issue with ASA anchors sometimes not created in time.
6+
57
## 1.5.3 - Remove dependency on tuple, and add MR Feature Tool support back to Unity 2018.4.
68

79
## 1.5.2 - Delay startup for Holographic Remoting.

UPM/asa_files/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.microsoft.mixedreality.wlt.asa",
33
"displayName": "WLT-ASA",
4-
"version": "1.5.3",
4+
"version": "1.5.4",
55
"unity": "2020.3",
66
"msftFeatureCategory": "World Locking Tools",
77
"description": "World Locking Tools for Unity (WLT) + Azure Spatial Anchors (ASA)\n\nThis optional add-on to WLT leverages ASA to persist coordinate spaces across sessions and share them across devices.\nCross platform support includes HoloLens, Android, and iOS.",
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"com.microsoft.azure.spatial-anchors-sdk.core": "2.9.0",
38-
"com.microsoft.mixedreality.worldlockingtools": "1.5.3"
38+
"com.microsoft.mixedreality.worldlockingtools": "1.5.4"
3939
},
4040
"files": [
4141
"WorldLocking.ASA",

UPM/asa_samples_files/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[See release notes](https://github.com/microsoft/MixedReality-WorldLockingTools-Unity/releases)
44

5+
## 1.5.4 - Fix timing issue with ASA anchors sometimes not created in time.
6+
57
## 1.5.3 - Remove dependency on tuple, and add MR Feature Tool support back to Unity 2018.4.
68

79
## 1.5.2 - Delay startup for Holographic Remoting.

UPM/asa_samples_files/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.microsoft.mixedreality.wlt.asa.samples",
33
"displayName": "WLT-ASA Samples",
4-
"version": "1.5.3",
4+
"version": "1.5.4",
55
"unity": "2020.3",
66
"msftFeatureCategory" : "World Locking Tools",
77
"description": "Example scenes and scripts leveraging Azure Space Anchors (ASA) to persist World Locked coordinate spaces across sessions and share across devices.\n\nFurther samples available at\nhttps://microsoft.github.io/MixedReality-WorldLockingTools-Samples/README.html",
@@ -36,9 +36,9 @@
3636
"dependencies": {
3737
"com.microsoft.azure.spatial-anchors-sdk.core": "2.9.0",
3838
"com.microsoft.mixedreality.toolkit.foundation": "2.7.0",
39-
"com.microsoft.mixedreality.wlt.asa": "1.5.3",
40-
"com.microsoft.mixedreality.worldlockingtools": "1.5.3",
41-
"com.microsoft.mixedreality.worldlockingsamples": "1.5.3"
39+
"com.microsoft.mixedreality.wlt.asa": "1.5.4",
40+
"com.microsoft.mixedreality.worldlockingtools": "1.5.4",
41+
"com.microsoft.mixedreality.worldlockingsamples": "1.5.4"
4242
},
4343
"files": [
4444
"package.json.meta",

UPM/core_files/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[See release notes](https://github.com/microsoft/MixedReality-WorldLockingTools-Unity/releases)
44

5+
## 1.5.4 - Backward compatibility for Unity 2018 .NET backend.
6+
57
## 1.5.3 - Remove dependency on tuple, and add MR Feature Tool support back to Unity 2018.4.
68

79
## 1.5.2 - Delay startup for Holographic Remoting.

0 commit comments

Comments
 (0)