/// <summary> /// Attempts to attach to an anchor by anchorName in the local store.. /// </summary> /// <returns>True if it attached, false if it could not attach</returns> private bool AttachToCachedAnchor(string CachedAnchorName) { if (string.IsNullOrEmpty(CachedAnchorName)) { Debug.Log("Ignoring empty name"); return(false); } UnityEngine.XR.WSA.Persistence.WorldAnchorStore anchorStore = WorldAnchorManager.Instance.AnchorStore; Debug.Log("Looking for " + CachedAnchorName); string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { if (ids[index] == CachedAnchorName) { Debug.Log("Using what we have"); anchorStore.Load(ids[index], objectToAnchor); AnchorEstablished = true; return(true); } else { Debug.Log(ids[index]); } } // Didn't find the anchor. return(false); }
/// <summary> /// Attempts to attach to an anchor by anchorName in the local store.. /// </summary> /// <returns>True if it attached, false if it could not attach</returns> private bool AttachToCachedAnchor(string anchorName) { if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Looking for " + anchorName); } string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { if (ids[index] == anchorName) { if (SharingStage.Instance.ShowDetailedLogs) { Debug.LogFormat("Attempting to load {0}...", anchorName); } UnityEngine.XR.WSA.WorldAnchor anchor = anchorStore.Load(ids[index], gameObject); if (anchor.isLocated) { AnchorLoadComplete(); } else { anchor.OnTrackingChanged += ImportExportAnchorManager_OnTrackingChanged_Attaching; currentState = ImportExportState.Ready; } return(true); } } // Didn't find the anchor. return(false); }
// Use this for initialization IEnumerator Start() { //mCol = GetComponent<Collider>(); if (deferredParent == null) { deferredParent = transform; } while (!WorldAnchorManager.IsInitialized) { yield return(null); } WorldErrors.Print("World Anchor Manager Initialized"); if (store == null) //store should be loaded once { WorldErrors.Print("Getting Store"); if (!GettingStore) { GettingStore = true; UnityEngine.XR.WSA.Persistence.WorldAnchorStore.GetAsync(GotStore); } while (store == null) { yield return(null); } WorldErrors.Print("Got Store"); } UnityEngine.XR.WSA.WorldAnchor wa = store.Load(anchorName, gameObject); if (wa == null) //no anchor found { WorldErrors.Print("No Anchor, creating one"); NoAnchor(); WorldAnchorManager.Instance.AttachAnchor(deferredParent.gameObject, anchorName); //StartCoroutine(AnchorTest()); } else { WorldErrors.Print("Loaded Anchor"); LoadedAnchor(); } yield return(null); }