Skip to content

Commit 527e864

Browse files
Merge pull request #742 from StephenHodgson/HTK-WorldAnchorManagerUpdate
Update to WorldAnchorManager and added MultiLens capabilities
2 parents 15df22e + b3c30a4 commit 527e864

24 files changed

+5697
-612
lines changed

Assets/HoloToolkit-Examples/SharingWithUNET/Scripts/UNetAnchorManager.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
5-
using System.Collections.Generic;
65
using UnityEngine.Networking;
7-
using HoloToolkit.Unity;
8-
using System;
96

107
#if UNITY_WSA
8+
using System;
9+
using System.Collections.Generic;
1110
using UnityEngine.VR.WSA.Sharing;
1211
using UnityEngine.VR.WSA;
1312
using UnityEngine.VR.WSA.Persistence;
13+
using HoloToolkit.Unity;
1414
#endif
1515

1616
namespace HoloToolkit.Examples.SharingWithUNET
@@ -38,23 +38,12 @@ public static UNetAnchorManager Instance
3838
}
3939
}
4040

41-
/// <summary>
42-
/// Sometimes we'll see a really small anchor blob get generated.
43-
/// These tend to not work, so we have a minimum trustable size.
44-
/// </summary>
45-
private const uint minTrustworthySerializedAnchorDataSize = 500000;
46-
4741
/// <summary>
4842
/// Keeps track of the name of the world anchor to use.
4943
/// </summary>
5044
[SyncVar]
5145
public string AnchorName = "";
5246

53-
/// <summary>
54-
/// List of bytes that represent the anchor data to export.
55-
/// </summary>
56-
private List<byte> exportingAnchorBytes = new List<byte>();
57-
5847
/// <summary>
5948
/// The UNet network manager in the scene.
6049
/// </summary>
@@ -65,15 +54,27 @@ public static UNetAnchorManager Instance
6554
/// </summary>
6655
private GenericNetworkTransmitter networkTransmitter;
6756

57+
#if UNITY_WSA
6858
/// <summary>
69-
/// Keeps track of if we created the anchor.
59+
/// The object to attach the anchor to when created or imported.
7060
/// </summary>
71-
private bool createdAnchor = false;
61+
private GameObject objectToAnchor;
7262

7363
/// <summary>
74-
/// The object to attach the anchor to when created or imported.
64+
/// Sometimes we'll see a really small anchor blob get generated.
65+
/// These tend to not work, so we have a minimum trustworthy size.
7566
/// </summary>
76-
private GameObject objectToAnchor;
67+
private const uint MinTrustworthySerializedAnchorDataSize = 500000;
68+
69+
/// <summary>
70+
/// List of bytes that represent the anchor data to export.
71+
/// </summary>
72+
private List<byte> exportingAnchorBytes = new List<byte>(0);
73+
74+
/// <summary>
75+
/// Keeps track of if we created the anchor.
76+
/// </summary>
77+
private bool createdAnchor = false;
7778

7879
/// <summary>
7980
/// Previous anchor name.
@@ -95,6 +96,7 @@ public static UNetAnchorManager Instance
9596
/// </summary>
9697
private string exportingAnchorName;
9798

99+
#endif
98100
/// <summary>
99101
/// Tracks if we have a shared anchor established
100102
/// </summary>
@@ -135,10 +137,10 @@ private bool CheckConfiguration()
135137
Debug.Log("No SharedCollection found in scene");
136138
return false;
137139
}
138-
else
139-
{
140+
141+
#if UNITY_WSA
140142
objectToAnchor = SharedCollection.Instance.gameObject;
141-
}
143+
#endif
142144

143145
return true;
144146
}
@@ -161,11 +163,13 @@ private void Start()
161163
/// <param name="data">The data blob to import.</param>
162164
private void NetworkTransmitter_dataReadyEvent(byte[] data)
163165
{
166+
#if UNITY_WSA
164167
Debug.Log("Anchor data arrived.");
165168
anchorData = data;
166169
Debug.Log(data.Length);
167170
DownloadingAnchor = false;
168171
gotOne = true;
172+
#endif
169173
}
170174

171175
/// <summary>
@@ -223,6 +227,7 @@ private bool AttachToCachedAnchor(string anchorName)
223227
return false;
224228
}
225229

230+
#if UNITY_WSA
226231
/// <summary>
227232
/// Called as anchor data becomes available to export
228233
/// </summary>
@@ -232,7 +237,6 @@ private void WriteBuffer(byte[] data)
232237
exportingAnchorBytes.AddRange(data);
233238
}
234239

235-
#if UNITY_WSA
236240
private void Update()
237241
{
238242
if (gotOne)
@@ -293,7 +297,7 @@ private void ImportComplete(SerializationCompletionReason status, WorldAnchorTra
293297
/// <param name="status">If the serialization succeeded.</param>
294298
private void ExportComplete(SerializationCompletionReason status)
295299
{
296-
if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize)
300+
if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize)
297301
{
298302
AnchorName = exportingAnchorName;
299303
anchorData = exportingAnchorBytes.ToArray();
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1001 &100100000
4+
Prefab:
5+
m_ObjectHideFlags: 1
6+
serializedVersion: 2
7+
m_Modification:
8+
m_TransformParent: {fileID: 0}
9+
m_Modifications: []
10+
m_RemovedComponents: []
11+
m_ParentPrefab: {fileID: 0}
12+
m_RootGameObject: {fileID: 1263896259355700}
13+
m_IsPrefabParent: 1
14+
--- !u!1 &1142360440761678
15+
GameObject:
16+
m_ObjectHideFlags: 0
17+
m_PrefabParentObject: {fileID: 0}
18+
m_PrefabInternal: {fileID: 100100000}
19+
serializedVersion: 5
20+
m_Component:
21+
- component: {fileID: 4097222579833928}
22+
- component: {fileID: 23794762112030164}
23+
- component: {fileID: 102277783203209222}
24+
m_Layer: 0
25+
m_Name: AnchorText
26+
m_TagString: Untagged
27+
m_Icon: {fileID: 0}
28+
m_NavMeshLayer: 0
29+
m_StaticEditorFlags: 0
30+
m_IsActive: 1
31+
--- !u!1 &1263896259355700
32+
GameObject:
33+
m_ObjectHideFlags: 0
34+
m_PrefabParentObject: {fileID: 0}
35+
m_PrefabInternal: {fileID: 100100000}
36+
serializedVersion: 5
37+
m_Component:
38+
- component: {fileID: 4181948179430244}
39+
- component: {fileID: 33232791332337668}
40+
- component: {fileID: 135521382791405888}
41+
- component: {fileID: 23351611205389120}
42+
- component: {fileID: 114202258574957562}
43+
m_Layer: 0
44+
m_Name: AnchorDebug
45+
m_TagString: Untagged
46+
m_Icon: {fileID: 0}
47+
m_NavMeshLayer: 0
48+
m_StaticEditorFlags: 0
49+
m_IsActive: 1
50+
--- !u!4 &4097222579833928
51+
Transform:
52+
m_ObjectHideFlags: 1
53+
m_PrefabParentObject: {fileID: 0}
54+
m_PrefabInternal: {fileID: 100100000}
55+
m_GameObject: {fileID: 1142360440761678}
56+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
57+
m_LocalPosition: {x: 0, y: 0.6, z: 0}
58+
m_LocalScale: {x: 0.024999999, y: 0.024999999, z: 0.024999999}
59+
m_Children: []
60+
m_Father: {fileID: 4181948179430244}
61+
m_RootOrder: 0
62+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
63+
--- !u!4 &4181948179430244
64+
Transform:
65+
m_ObjectHideFlags: 1
66+
m_PrefabParentObject: {fileID: 0}
67+
m_PrefabInternal: {fileID: 100100000}
68+
m_GameObject: {fileID: 1263896259355700}
69+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
70+
m_LocalPosition: {x: 0, y: 0, z: 0}
71+
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
72+
m_Children:
73+
- {fileID: 4097222579833928}
74+
m_Father: {fileID: 0}
75+
m_RootOrder: 0
76+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
77+
--- !u!23 &23351611205389120
78+
MeshRenderer:
79+
m_ObjectHideFlags: 1
80+
m_PrefabParentObject: {fileID: 0}
81+
m_PrefabInternal: {fileID: 100100000}
82+
m_GameObject: {fileID: 1263896259355700}
83+
m_Enabled: 1
84+
m_CastShadows: 1
85+
m_ReceiveShadows: 1
86+
m_MotionVectors: 1
87+
m_LightProbeUsage: 1
88+
m_ReflectionProbeUsage: 1
89+
m_Materials:
90+
- {fileID: 2100000, guid: 474f0e0481d4aa14e92a5ada98042f3a, type: 2}
91+
m_StaticBatchInfo:
92+
firstSubMesh: 0
93+
subMeshCount: 0
94+
m_StaticBatchRoot: {fileID: 0}
95+
m_ProbeAnchor: {fileID: 0}
96+
m_LightProbeVolumeOverride: {fileID: 0}
97+
m_ScaleInLightmap: 1
98+
m_PreserveUVs: 1
99+
m_IgnoreNormalsForChartDetection: 0
100+
m_ImportantGI: 0
101+
m_SelectedEditorRenderState: 3
102+
m_MinimumChartSize: 4
103+
m_AutoUVMaxDistance: 0.5
104+
m_AutoUVMaxAngle: 89
105+
m_LightmapParameters: {fileID: 0}
106+
m_SortingLayerID: 0
107+
m_SortingLayer: 0
108+
m_SortingOrder: 0
109+
--- !u!23 &23794762112030164
110+
MeshRenderer:
111+
m_ObjectHideFlags: 1
112+
m_PrefabParentObject: {fileID: 0}
113+
m_PrefabInternal: {fileID: 100100000}
114+
m_GameObject: {fileID: 1142360440761678}
115+
m_Enabled: 1
116+
m_CastShadows: 1
117+
m_ReceiveShadows: 1
118+
m_MotionVectors: 1
119+
m_LightProbeUsage: 1
120+
m_ReflectionProbeUsage: 1
121+
m_Materials:
122+
- {fileID: 10100, guid: 0000000000000000e000000000000000, type: 0}
123+
m_StaticBatchInfo:
124+
firstSubMesh: 0
125+
subMeshCount: 0
126+
m_StaticBatchRoot: {fileID: 0}
127+
m_ProbeAnchor: {fileID: 0}
128+
m_LightProbeVolumeOverride: {fileID: 0}
129+
m_ScaleInLightmap: 1
130+
m_PreserveUVs: 0
131+
m_IgnoreNormalsForChartDetection: 0
132+
m_ImportantGI: 0
133+
m_SelectedEditorRenderState: 3
134+
m_MinimumChartSize: 4
135+
m_AutoUVMaxDistance: 0.5
136+
m_AutoUVMaxAngle: 89
137+
m_LightmapParameters: {fileID: 0}
138+
m_SortingLayerID: 0
139+
m_SortingLayer: 0
140+
m_SortingOrder: 0
141+
--- !u!33 &33232791332337668
142+
MeshFilter:
143+
m_ObjectHideFlags: 1
144+
m_PrefabParentObject: {fileID: 0}
145+
m_PrefabInternal: {fileID: 100100000}
146+
m_GameObject: {fileID: 1263896259355700}
147+
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
148+
--- !u!102 &102277783203209222
149+
TextMesh:
150+
serializedVersion: 3
151+
m_ObjectHideFlags: 1
152+
m_PrefabParentObject: {fileID: 0}
153+
m_PrefabInternal: {fileID: 100100000}
154+
m_GameObject: {fileID: 1142360440761678}
155+
m_Text: No Server Connection
156+
m_OffsetZ: 0
157+
m_CharacterSize: 1
158+
m_LineSpacing: 1
159+
m_Anchor: 7
160+
m_Alignment: 1
161+
m_TabSize: 4
162+
m_FontSize: 48
163+
m_FontStyle: 0
164+
m_RichText: 1
165+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
166+
m_Color:
167+
serializedVersion: 2
168+
rgba: 4294967295
169+
--- !u!114 &114202258574957562
170+
MonoBehaviour:
171+
m_ObjectHideFlags: 1
172+
m_PrefabParentObject: {fileID: 0}
173+
m_PrefabInternal: {fileID: 100100000}
174+
m_GameObject: {fileID: 1263896259355700}
175+
m_Enabled: 1
176+
m_EditorHideFlags: 0
177+
m_Script: {fileID: 11500000, guid: ac8d5b128a1d8204fb76c86f47b75912, type: 3}
178+
m_Name:
179+
m_EditorClassIdentifier:
180+
PivotAxis: 0
181+
--- !u!135 &135521382791405888
182+
SphereCollider:
183+
m_ObjectHideFlags: 1
184+
m_PrefabParentObject: {fileID: 0}
185+
m_PrefabInternal: {fileID: 100100000}
186+
m_GameObject: {fileID: 1263896259355700}
187+
m_Material: {fileID: 0}
188+
m_IsTrigger: 0
189+
m_Enabled: 1
190+
serializedVersion: 2
191+
m_Radius: 0.5
192+
m_Center: {x: 0, y: 0, z: 0}

Assets/HoloToolkit-Tests/Sharing/Prefabs/AnchorDebug.prefab.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)