/// <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 IEnumerator PlaceWorldAnchor() { // Wait while the SR loads a bit. yield return(new WaitForSeconds(0.5f)); if (m_PointOfReference) { DestroyImmediate(m_PointOfReference); } m_PointOfReferenceCube.transform.position = Vector3.zero; m_PointOfReferenceCube.transform.localScale = Vector3.one * 0.1f; m_PointOfReference = store.Load(PointOfReferenceID, m_PointOfReferenceCube); if (m_PointOfReference == null) { if (StatusText.Instance) { StatusText.Instance.SetText("No Point of Reference created."); } } else { Debug.Log("Created anchor from WorldAnchorStore: " + PointOfReferenceID); if (StatusText.Instance) { StatusText.Instance.SetText("Loaded WorldAnchorStore"); } } }
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; Debug.Log("looking for " + ObjectAnchorStoreName); anchorStore.Load(ObjectAnchorStoreName, gameObject); UnityEngine.XR.WSA.WorldAnchor anchor = gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (anchor != null) { Destroy(anchor); } }
public void CreateAnchor() { 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 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; } } }
/// <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); }