Skip to content

Commit 3f3cafb

Browse files
Merge pull request #539 from VincentGuigui/master
Adding a Remove All Anchors method in WorldAnchorManager
2 parents 818815d + 37f0b91 commit 3f3cafb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs

Lines changed: 35 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,40 @@ 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+
SpatialMappingManager spatialMappingManager = SpatialMappingManager.Instance;
145+
146+
// This case is unexpected, but just in case.
147+
if (AnchorStore == null)
148+
{
149+
Debug.LogError("remove all anchors called before anchor store is ready.");
150+
}
151+
152+
WorldAnchor[] anchors = FindObjectsOfType<WorldAnchor>();
153+
154+
if (anchors != null)
155+
{
156+
foreach (WorldAnchor anchor in anchors)
157+
{
158+
// Don't remove SpatialMapping anchors if exists
159+
if (spatialMappingManager == null ||
160+
anchor.gameObject.transform.parent.gameObject != spatialMappingManager.gameObject)
161+
{
162+
anchorOperations.Enqueue(new AnchorAttachmentInfo()
163+
{
164+
AnchorName = anchor.name,
165+
GameObjectToAnchor = anchor.gameObject,
166+
Operation = AnchorOperation.Delete
167+
});
168+
}
169+
}
170+
}
171+
}
172+
138173
/// <summary>
139174
/// Function that actually adds the anchor to the game object.
140175
/// </summary>

0 commit comments

Comments
 (0)