public void StartPlacing() { if (anchorStore == null) { return; } UnityEngine.XR.WSA.WorldAnchor anchor = gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (anchor != null) { DestroyImmediate(anchor); } string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { Debug.Log(ids[index]); if (ids[index] == ObjectAnchorStoreName) { bool deleted = anchorStore.Delete(ids[index]); Debug.Log("deleted: " + deleted); break; } } }
/// <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) { Debug.Log("Looking for " + anchorName); string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { if (ids[index] == anchorName) { Debug.Log("Using what we have"); UnityEngine.XR.WSA.WorldAnchor wa = anchorStore.Load(ids[index], gameObject); if (wa.isLocated) { currentState = ImportExportState.Ready; } else { wa.OnTrackingChanged += ImportExportAnchorManager_OnTrackingChanged_Attaching; } return(true); } } // Didn't find the anchor. return(false); }
void AnchorStoreReady(UnityEngine.XR.WSA.Persistence.WorldAnchorStore store) { anchorStore = store; string[] ids = anchorStore.GetAllIds(); foreach (GameObject marker in Markers) { // Retrieve WorldAnchors for each marker if it exists Debug.Log("Looking for " + marker.name + " in WorldAnchorStore"); UnityEngine.XR.WSA.WorldAnchor wa = anchorStore.Load(marker.name, marker); if (wa != null) { Debug.Log("Retrieved anchor from WorldAnchorStore"); } else { // Set new WorldAnchor if no existing WorldAnchor found Debug.Log("No WorldAnchor for " + marker.name + " found, creating new WorldAnchor"); UnityEngine.XR.WSA.WorldAnchor attachingAnchor = marker.AddComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (attachingAnchor.isLocated) { bool saved = anchorStore.Save(marker.name, attachingAnchor); Debug.Log("Saved new WorldAnchor position for " + marker.name + ": " + saved); } else { attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged; } } } }
private bool AttachToCachedAnchor(string anchorName) { Debug.LogFormat("Anchor Manager: Looking for Remote Anchor: {0}", anchorName); DebugDisplay(string.Format("\nLooking for Remote Anchor: {0}", anchorName)); string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { if (ids[index] == anchorName) { Debug.LogFormat("Anchor Manager: Attempting to Load CACHED Anchor {0}", anchorName); DebugDisplay(string.Format("\nAttempting to Load CACHED anchor {0}", anchorName)); UnityEngine.XR.WSA.WorldAnchor anchor = anchorStore.Load(ids[index], gameObject); if (anchor.isLocated) { // TODO: Notify Anchor is Located IsAnchorLocated = true; } else { IsAnchorLocated = false; DebugDisplay(string.Format("\nAnchor: {0} - Not Located", anchorName)); anchor.OnTrackingChanged += ImportExportAnchorManager_OnTrackingChanged_Attaching; } return(true); } } // Didn't find the anchor, so we'll download from room. return(false); }
void AnchorStoreReady(UnityEngine.XR.WSA.Persistence.WorldAnchorStore store) { anchorStore = store; Placing = true; Debug.Log("looking for " + ObjectAnchorStoreName); string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { Debug.Log(ids[index]); if (ids[index] == ObjectAnchorStoreName) { UnityEngine.XR.WSA.WorldAnchor wa = anchorStore.Load(ids[index], gameObject); Placing = false; break; } } }
void OnSelect() { if (anchorStore == null) { return; } if (Placing) { UnityEngine.XR.WSA.WorldAnchor attachingAnchor = gameObject.AddComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (attachingAnchor.isLocated) { Debug.Log("Saving persisted position immediately"); bool saved = anchorStore.Save(ObjectAnchorStoreName, attachingAnchor); Debug.Log("saved: " + saved); } else { attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged; } } else { UnityEngine.XR.WSA.WorldAnchor anchor = gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (anchor != null) { DestroyImmediate(anchor); } string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { Debug.Log(ids[index]); if (ids[index] == ObjectAnchorStoreName) { bool deleted = anchorStore.Delete(ids[index]); Debug.Log("deleted: " + deleted); break; } } } Placing = !Placing; }
/// <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) { UnityEngine.XR.WSA.Persistence.WorldAnchorStore anchorStore = WorldAnchorManager.Instance.AnchorStore; Debug.Log("Looking for " + AnchorName); string[] ids = anchorStore.GetAllIds(); for (int index = 0; index < ids.Length; index++) { if (ids[index] == AnchorName) { Debug.Log("Using what we have"); anchorStore.Load(ids[index], objectToAnchor); AnchorEstablished = true; return(true); } } // Didn't find the anchor. return(false); }