Skip to content

Commit 5b6da6d

Browse files
committed
Simplified the testing process and WorldAnchorManager
1 parent 5b14c9b commit 5b6da6d

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

Assets/HoloToolkit-UnitTests/Editor/Utilities/Extensions/WorldAnchorManagerExtensions.cs

-16
This file was deleted.

Assets/HoloToolkit-UnitTests/Editor/Utilities/Extensions/WorldAnchorManagerExtensions.cs.meta

-12
This file was deleted.

Assets/HoloToolkit-UnitTests/Editor/Utilities/WorldAnchorManagerTests.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using UnityEngine;
22
using NUnit.Framework;
3-
using HoloToolkit.Unity.Tests.Extensions;
43

54
namespace HoloToolkit.Unity.Tests
65
{
@@ -10,16 +9,14 @@ public class WorldAnchorManagerTests
109
public void ClearScene()
1110
{
1211
TestUtils.ClearScene();
13-
var managers = new GameObject("Managers");
14-
managers.AddComponent<WorldAnchorManager>();
1512
}
1613

1714
[Test]
1815
public void TestGenerateAnchorNameFromGameObject()
1916
{
2017
const string expected = "AnchorName";
2118
var gameObject = new GameObject(expected);
22-
var result = WorldAnchorManager.Instance.GenerateAnchorName(gameObject);
19+
var result = WorldAnchorManager.GenerateAnchorName(gameObject);
2320
Assert.That(result, Is.EqualTo(expected));
2421
}
2522

@@ -28,7 +25,7 @@ public void TestGenerateAnchorNameFromParameter()
2825
{
2926
const string expected = "AnchorName";
3027
var gameObject = new GameObject();
31-
var result = WorldAnchorManager.Instance.GenerateAnchorName(gameObject, expected);
28+
var result = WorldAnchorManager.GenerateAnchorName(gameObject, expected);
3229
Assert.That(result, Is.EqualTo(expected));
3330
}
3431
}

Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ private void Anchor_OnTrackingChanged(WorldAnchor anchor, bool located)
170170

171171
#endregion // Event Callbacks
172172
#endif
173+
/// <summary>
174+
/// Generates the name for the anchor.
175+
/// If no anchor name was specified, the name of the anchor will be the same as the GameObject's name.
176+
/// </summary>
177+
/// <param name="gameObjectToAnchor">The GameObject to attach the anchor to.</param>
178+
/// <param name="proposedAnchorname">Name of the anchor. If none provided, the name of the GameObject will be used.</param>
179+
/// <returns>The name of the newly attached anchor.</returns>
180+
public static string GenerateAnchorName(GameObject gameObjectToAnchor, string proposedAnchorname = null)
181+
{
182+
return string.IsNullOrEmpty(proposedAnchorname) ? gameObjectToAnchor.name : proposedAnchorname;
183+
}
173184

174185
/// <summary>
175186
/// Attaches an anchor to the GameObject.
@@ -198,7 +209,7 @@ public string AttachAnchor(GameObject gameObjectToAnchor, string anchorName = nu
198209
Debug.LogWarning("[WorldAnchorManager] AttachAnchor called before anchor store is ready.");
199210
}
200211

201-
anchorName = string.IsNullOrEmpty(anchorName) ? gameObjectToAnchor.name : anchorName;
212+
anchorName = GenerateAnchorName(gameObjectToAnchor, anchorName);
202213

203214
LocalAnchorOperations.Enqueue(
204215
new AnchorAttachmentInfo

0 commit comments

Comments
 (0)