Skip to content

Commit fc94dc1

Browse files
author
Regis WANG
committed
in debug mode, create local anchor process often stuck without located or any event triggered. changed back to origin code version, letting the local anchor created on demand instead of always during Start phase.
1 parent 7a3264e commit fc94dc1

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

Assets/HoloToolkit/Sharing/Tests/Scripts/ImportExportAnchorManager.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ private static bool ShouldLocalUserCreateRoom
132132
/// </summary>
133133
private WorldAnchorStore anchorStore;
134134

135-
/// <summary>
136-
/// The anchor this object is attached to.
137-
/// </summary>
138-
private WorldAnchor thisAnchor;
139-
140135
/// <summary>
141136
/// Keeps track of the name of the anchor we are exporting.
142137
/// </summary>
@@ -220,9 +215,6 @@ protected override void Awake()
220215

221216
private void Start()
222217
{
223-
#if UNITY_WSA && !UNITY_EDITOR
224-
thisAnchor = GetComponent<WorldAnchor>() ?? gameObject.AddComponent<WorldAnchor>();
225-
#endif
226218
// SharingStage should be valid at this point, but we may not be connected.
227219
if (SharingStage.Instance.IsConnected)
228220
{
@@ -701,13 +693,14 @@ private void AnchorStoreReady(WorldAnchorStore store)
701693
/// </summary>
702694
private void CreateAnchorLocally()
703695
{
704-
if (thisAnchor.isLocated)
696+
WorldAnchor anchor = this.EnsureComponent<WorldAnchor>();
697+
if (anchor.isLocated)
705698
{
706699
currentState = ImportExportState.ReadyToExportInitialAnchor;
707700
}
708701
else
709702
{
710-
thisAnchor.OnTrackingChanged += Anchor_OnTrackingChanged_InitialAnchor;
703+
anchor.OnTrackingChanged += Anchor_OnTrackingChanged_InitialAnchor;
711704
}
712705
}
713706

@@ -883,11 +876,12 @@ private void AnchorLoadComplete()
883876
/// </summary>
884877
private void Export()
885878
{
879+
WorldAnchor anchor = this.GetComponent<WorldAnchor>();
886880
string guidString = Guid.NewGuid().ToString();
887881
exportingAnchorName = guidString;
888882

889883
// Save the anchor to our local anchor store.
890-
if (thisAnchor != null && anchorStore.Save(exportingAnchorName, thisAnchor))
884+
if (anchor != null && anchorStore.Save(exportingAnchorName, anchor))
891885
{
892886
if (SharingStage.Instance.ShowDetailedLogs)
893887
{
@@ -900,7 +894,7 @@ private void Export()
900894
}
901895

902896
sharedAnchorInterface = new WorldAnchorTransferBatch();
903-
sharedAnchorInterface.AddWorldAnchor(guidString, thisAnchor);
897+
sharedAnchorInterface.AddWorldAnchor(guidString, anchor);
904898
WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete);
905899
}
906900
else

0 commit comments

Comments
 (0)