Skip to content

Commit 5ab7ac9

Browse files
committed
addressing feedback from review
1 parent 40fd264 commit 5ab7ac9

File tree

2 files changed

+60
-38
lines changed

2 files changed

+60
-38
lines changed

Assets/HoloToolkit/SpatialMapping/Scripts/TapToPlace.cs

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,64 @@ public partial class TapToPlace : MonoBehaviour
2626
/// </summary>
2727
WorldAnchorManager anchorManager;
2828

29+
/// <summary>
30+
/// Controls spatial mapping. In this script we access spatialMappingManager
31+
/// to control rendering and to access the physics layer mask.
32+
/// </summary>
33+
SpatialMappingManager spatialMappingManager;
34+
35+
/// <summary>
36+
/// Keeps track of if the user is moving the object or not.
37+
/// </summary>
2938
bool placing = false;
3039

3140
void Start()
3241
{
42+
// Make sure we have all the components in the scene we need.
3343
anchorManager = WorldAnchorManager.Instance;
34-
anchorManager.AttachAnchor(this.gameObject, SavedAnchorFriendlyName);
44+
if (anchorManager == null)
45+
{
46+
Debug.LogError("This script expects that you have a WorldAnchorManager component in your scene.");
47+
}
48+
49+
spatialMappingManager = SpatialMappingManager.Instance;
50+
if (spatialMappingManager == null)
51+
{
52+
Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
53+
}
54+
55+
if (anchorManager != null && spatialMappingManager != null)
56+
{
57+
anchorManager.AttachAnchor(this.gameObject, SavedAnchorFriendlyName);
58+
}
59+
else
60+
{
61+
// If we don't have what we need to proceed, we may as well remove ourselves.
62+
Destroy(this);
63+
}
3564
}
3665

3766
// Called by GazeGestureManager when the user performs a tap gesture.
3867
void OnSelect()
3968
{
40-
if (SpatialMappingManager.Instance != null)
41-
{
42-
// On each tap gesture, toggle whether the user is in placing mode.
43-
placing = !placing;
69+
// On each tap gesture, toggle whether the user is in placing mode.
70+
placing = !placing;
4471

45-
// If the user is in placing mode, display the spatial mapping mesh.
46-
if (placing)
47-
{
48-
SpatialMappingManager.Instance.DrawVisualMeshes = true;
72+
// If the user is in placing mode, display the spatial mapping mesh.
73+
if (placing)
74+
{
75+
spatialMappingManager.DrawVisualMeshes = true;
4976

50-
Debug.Log(gameObject.name + " : Removing existing world anchor if any.");
77+
Debug.Log(gameObject.name + " : Removing existing world anchor if any.");
5178

52-
anchorManager.RemoveAnchor(gameObject);
53-
}
54-
// If the user is not in placing mode, hide the spatial mapping mesh.
55-
else
56-
{
57-
SpatialMappingManager.Instance.DrawVisualMeshes = false;
58-
// Add world anchor when object placement is done.
59-
anchorManager.AttachAnchor(gameObject, SavedAnchorFriendlyName);
60-
}
79+
anchorManager.RemoveAnchor(gameObject);
6180
}
81+
// If the user is not in placing mode, hide the spatial mapping mesh.
6282
else
6383
{
64-
Debug.Log("TapToPlace requires spatial mapping. Try adding SpatialMapping prefab to project.");
84+
spatialMappingManager.DrawVisualMeshes = false;
85+
// Add world anchor when object placement is done.
86+
anchorManager.AttachAnchor(gameObject, SavedAnchorFriendlyName);
6587
}
6688
}
6789

@@ -77,7 +99,7 @@ void Update()
7799

78100
RaycastHit hitInfo;
79101
if (Physics.Raycast(headPosition, gazeDirection, out hitInfo,
80-
30.0f, SpatialMappingManager.Instance.LayerMask))
102+
30.0f, spatialMappingManager.LayerMask))
81103
{
82104
// Move this object to where the raycast
83105
// hit the Spatial Mapping mesh.

Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class WorldAnchorManager : Singleton<WorldAnchorManager>
2323
/// </summary>
2424
private struct AnchorAttachmentInfo
2525
{
26-
public GameObject gameObjectToAnchor { get; set; }
27-
public string anchorName { get; set; }
26+
public GameObject GameObjectToAnchor { get; set; }
27+
public string AnchorName { get; set; }
2828
}
2929

3030
/// <summary>
@@ -36,23 +36,23 @@ private struct AnchorAttachmentInfo
3636
/// The WorldAnchorStore for the current application.
3737
/// Can be null when the application starts.
3838
/// </summary>
39-
public WorldAnchorStore anchorStore { get; set; }
39+
public WorldAnchorStore AnchorStore { get; private set; }
4040

4141
/// <summary>
4242
/// Callback function that contains the WorldAnchorStore object.
4343
/// </summary>
4444
/// <param name="Store">The WorldAnchorStore to cache.</param>
4545
void AnchorStoreReady(WorldAnchorStore Store)
4646
{
47-
anchorStore = Store;
47+
AnchorStore = Store;
4848
}
4949

5050
/// <summary>
5151
/// When the app starts grab the anchor store immediately.
5252
/// </summary>
5353
void Awake()
5454
{
55-
anchorStore = null;
55+
AnchorStore = null;
5656
WorldAnchorStore.GetAsync(AnchorStoreReady);
5757
}
5858

@@ -61,7 +61,7 @@ void Awake()
6161
/// </summary>
6262
void Update()
6363
{
64-
if (anchorStore != null && anchorOperations.Count > 0)
64+
if (AnchorStore != null && anchorOperations.Count > 0)
6565
{
6666
DoAnchorOperation(anchorOperations.Dequeue());
6767
}
@@ -73,16 +73,16 @@ void Update()
7373
/// a new anchor will be saved under the specified name.
7474
/// </summary>
7575
/// <param name="gameObjectToAnchor">The Gameobject to attach the anchor to.</param>
76-
/// <param name="AnchorName">Name of the anchor.</param>
77-
public void AttachAnchor(GameObject gameObjectToAnchor, string AnchorName)
76+
/// <param name="anchorName">Name of the anchor.</param>
77+
public void AttachAnchor(GameObject gameObjectToAnchor, string anchorName)
7878
{
7979
if (gameObjectToAnchor == null)
8080
{
8181
Debug.LogError("Must pass in a valid gameObject");
8282
return;
8383
}
8484

85-
if (string.IsNullOrEmpty(AnchorName))
85+
if (string.IsNullOrEmpty(anchorName))
8686
{
8787
Debug.LogError("Must supply an AnchorName.");
8888
return;
@@ -91,8 +91,8 @@ public void AttachAnchor(GameObject gameObjectToAnchor, string AnchorName)
9191
anchorOperations.Enqueue(
9292
new AnchorAttachmentInfo()
9393
{
94-
gameObjectToAnchor = gameObjectToAnchor,
95-
anchorName = AnchorName
94+
GameObjectToAnchor = gameObjectToAnchor,
95+
AnchorName = anchorName
9696
}
9797
);
9898
}
@@ -105,7 +105,7 @@ public void AttachAnchor(GameObject gameObjectToAnchor, string AnchorName)
105105
public void RemoveAnchor(GameObject gameObjectToUnanchor)
106106
{
107107
// This case is unexpected, but just in case.
108-
if (anchorStore == null)
108+
if (AnchorStore == null)
109109
{
110110
Debug.LogError("remove anchor called before anchor store is ready.");
111111
}
@@ -114,7 +114,7 @@ public void RemoveAnchor(GameObject gameObjectToUnanchor)
114114

115115
if (anchor != null)
116116
{
117-
anchorStore.Delete(anchor.name);
117+
AnchorStore.Delete(anchor.name);
118118
DestroyImmediate(anchor);
119119
}
120120
}
@@ -125,8 +125,8 @@ public void RemoveAnchor(GameObject gameObjectToUnanchor)
125125
/// <param name="anchorAttachmentInfo">Parameters for attaching the anchor.</param>
126126
void DoAnchorOperation(AnchorAttachmentInfo anchorAttachmentInfo)
127127
{
128-
string AnchorName = anchorAttachmentInfo.anchorName;
129-
GameObject gameObjectToAnchor = anchorAttachmentInfo.gameObjectToAnchor;
128+
string AnchorName = anchorAttachmentInfo.AnchorName;
129+
GameObject gameObjectToAnchor = anchorAttachmentInfo.GameObjectToAnchor;
130130

131131
if (gameObjectToAnchor == null)
132132
{
@@ -135,7 +135,7 @@ void DoAnchorOperation(AnchorAttachmentInfo anchorAttachmentInfo)
135135
}
136136

137137
// Try to load a previously saved world anchor.
138-
WorldAnchor savedAnchor = anchorStore.Load(AnchorName, gameObjectToAnchor);
138+
WorldAnchor savedAnchor = AnchorStore.Load(AnchorName, gameObjectToAnchor);
139139
if (savedAnchor == null)
140140
{
141141
// Either world anchor was not saved / does not exist or has a different name.
@@ -203,7 +203,7 @@ private void Anchor_OnTrackingChanged(WorldAnchor self, bool located)
203203
private void SaveAnchor(WorldAnchor anchor)
204204
{
205205
// Save the anchor to persist holograms across sessions.
206-
if (anchorStore.Save(anchor.name, anchor))
206+
if (AnchorStore.Save(anchor.name, anchor))
207207
{
208208
Debug.Log(gameObject.name + " : World anchor saved successfully.");
209209
}

0 commit comments

Comments
 (0)