private void ExportLocalAnchor()
    {
        CurrentState = AnchorManagementState.ExportingLocalAnchor;

        UnityEngine.XR.WSA.WorldAnchor anchor = gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>();
        string guidString = Guid.NewGuid().ToString();

        exportingAnchorName = guidString;

        // Save the anchor to our local anchor store.
        if (anchor != null && anchorStore.Save(exportingAnchorName, anchor))
        {
            Debug.LogFormat("Exporting anchor: {0}", exportingAnchorName);
            DebugDisplay(string.Format("\nExporting anchor: {0}", exportingAnchorName));

            sharedAnchorInterface = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch();
            sharedAnchorInterface.AddWorldAnchor(guidString, anchor);
            UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportLocalAnchorComplete);
        }
        else
        {
            Debug.LogWarning("Anchor Manager: Failed to export anchor, trying again...");
            DebugDisplay(string.Format("\nFailed to export anchor, trying again..."));

            CurrentState = AnchorManagementState.LocalAnchorExportFailed;
        }
    }
Esempio n. 2
0
    public bool SetMarker(int marker)
    {
        int idx = marker - 1;

        if (marker > Markers.Count)
        {
            return(false);
        }


        //RaycastHit hitInfo;
        /*Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo)*/
        if (RosGazeManager.Instance.Focused)
        {
            if (anchorStore == null)
            {
                return(false);
            }

            // Delete WorldAnchor if selected marker currently has one
            UnityEngine.XR.WSA.WorldAnchor anchor = Markers[idx].GetComponent <UnityEngine.XR.WSA.WorldAnchor>();
            if (anchor != null)
            {
                DestroyImmediate(anchor);
            }
            anchorStore.Delete(Markers[idx].name);

            // Move marker to new position
            Markers[idx].transform.position = RosGazeManager.Instance.position;

            // Set new WorldAnchor
            UnityEngine.XR.WSA.WorldAnchor attachingAnchor = Markers[idx].AddComponent <UnityEngine.XR.WSA.WorldAnchor>();
            if (attachingAnchor.isLocated)
            {
                bool saved = anchorStore.Save(Markers[idx].name, attachingAnchor);
                Debug.Log("Saved new WorldAnchor position for " + Markers[idx].name + ": " + saved);
            }
            else
            {
                attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged;
            }

            // return success
            return(true);
        }


        return(false);
    }
Esempio n. 3
0
 void PerformManipulationStop()
 {
     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);
         DestroyImmediate(attachingAnchor);
     }
     else
     {
         attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged;
     }
 }
Esempio n. 4
0
    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 void SaveAnchorToStore(string id, UnityEngine.XR.WSA.WorldAnchor worldAnchor)
    {
#if !UNITY_EDITOR
        if ((store != null) && (store.Save(id, worldAnchor)))
        {
            Debug.Log("WorldAnchor Saved: " + id);
            if (OnPlacement != null)
            {
                OnPlacement();
            }
        }
        else
        {
            Debug.Log("Failed to Save WorldAnchor " + id);
        }
#else
        if (OnPlacement != null)
        {
            OnPlacement();
        }
#endif
        if (StatusText.Instance)
        {
            StatusText.Instance.SetText("Anchor Saved");
        }
    }
Esempio n. 6
0
    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;
    }
Esempio n. 7
0
    /// <summary>
    /// Called when a remote anchor has been deserialized
    /// </summary>
    /// <param name="status"></param>
    /// <param name="wat"></param>
    private void ImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch wat)
    {
        if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0)
        {
            Debug.Log("Import complete");

            string first = wat.GetAllIds()[0];
            Debug.Log("Anchor name: " + first);

            UnityEngine.XR.WSA.WorldAnchor anchor = wat.LockObject(first, gameObject);
            anchorStore.Save(first, anchor);
            currentState = ImportExportState.Ready;
        }
        else
        {
            Debug.Log("Import fail");
            currentState = ImportExportState.DataReady;
        }
    }
Esempio n. 8
0
    public void StopPlacing()
    {
        if (anchorStore == null)
        {
            return;
        }

        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;
        }
    }