Skip to content

Commit 36a4380

Browse files
committed
Adding a Remove All Anchors.
It will remove all user anchors from the scene (anchors generated from Spatial Mapping and Surface Observer won't be removed)
1 parent 818815d commit 36a4380

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using UnityEngine;
66
using UnityEngine.VR.WSA.Persistence;
77
using UnityEngine.VR.WSA;
8+
using HoloToolkit.Unity.SpatialMapping;
89

910
namespace HoloToolkit.Unity
1011
{
@@ -135,6 +136,36 @@ public void RemoveAnchor(GameObject gameObjectToUnanchor)
135136
});
136137
}
137138

139+
/// <summary>
140+
/// Removes all anchors from the scene and deletes them from the anchor store.
141+
/// </summary>
142+
public void RemoveAllAnchors()
143+
{
144+
// This case is unexpected, but just in case.
145+
if (AnchorStore == null)
146+
{
147+
Debug.LogError("remove all anchors called before anchor store is ready.");
148+
}
149+
150+
WorldAnchor[] anchors = FindObjectsOfType<WorldAnchor>();
151+
SpatialMappingManager spatialMappingManager = FindObjectOfType<SpatialMappingManager>();
152+
153+
if (anchors != null)
154+
{
155+
foreach (WorldAnchor anchor in anchors)
156+
{
157+
//Don't remove SpatialMapping anchors
158+
if (anchor.gameObject.transform.parent.gameObject != spatialMappingManager.gameObject)
159+
anchorOperations.Enqueue(new Unity.WorldAnchorManager.AnchorAttachmentInfo()
160+
{
161+
AnchorName = anchor.name,
162+
GameObjectToAnchor = anchor.gameObject,
163+
Operation = AnchorOperation.Delete
164+
});
165+
}
166+
}
167+
}
168+
138169
/// <summary>
139170
/// Function that actually adds the anchor to the game object.
140171
/// </summary>

0 commit comments

Comments
 (0)