The WorldAnchor component allows a GameObject's position to be locked in physical space.

Inheritance: UnityEngine.Component
            //private void InternalDeleteWA(WorldAnchor wa)
            //{
            //    throw new NotImplementedException();
            //}

            public void DeleteWorldAnchor(TrackableBehaviour trackableBehaviour)
            {
                UnityEngine.VR.WSA.WorldAnchor wa = trackableBehaviour.GetComponent <UnityEngine.VR.WSA.WorldAnchor>();
                if (wa != null)
                {
                    if (mWorldAnchors.ContainsValue(wa))
                    {
                        // find all occurrences of that world anchor and remove them from the dict:
                        List <TrackableIdPair> idsToRemove = new List <TrackableIdPair>();
                        foreach (KeyValuePair <TrackableIdPair, UnityEngine.VR.WSA.WorldAnchor> kvp in mWorldAnchors)
                        {
                            if (kvp.Value == wa)
                            {
                                idsToRemove.Add(kvp.Key);
                            }
                        }

                        foreach (TrackableIdPair trackableIdPair in idsToRemove)
                        {
                            mWorldAnchors.Remove(trackableIdPair);
                        }
                    }

                    InternalDeleteWA(wa);
                }
            }
Example #2
0
 private static void Internal_TriggerEventOnTrackingLost(WorldAnchor self, bool located)
 {
     if ((self != null) && (self.OnTrackingChanged != null))
     {
         self.OnTrackingChanged(self, located);
     }
 }
 public void SetWorldAnchor(TrackableBehaviour trackableBehaviour, TrackableIdPair trackableID)
 {
     // add a world anchor to the given trackablebehaviour
     UnityEngine.VR.WSA.WorldAnchor wa = trackableBehaviour.gameObject.AddComponent <UnityEngine.VR.WSA.WorldAnchor>();
     mWorldAnchors[trackableID] = wa;
     // register for callbacks
     wa.OnTrackingChanged += OnWorldAnchorTrackingChanged;
 }
Example #4
0
 /// <summary>
 /// <para>Constructor for conveniently filling out a SurfaceData struct.</para>
 /// </summary>
 /// <param name="_id">ID for the surface in question.</param>
 /// <param name="_outputMesh">MeshFilter to write Mesh data to.</param>
 /// <param name="_outputAnchor">WorldAnchor receiving the anchor point for the surface.</param>
 /// <param name="_outputCollider">MeshCollider to write baked physics data to (optional).</param>
 /// <param name="_trianglesPerCubicMeter">Requested resolution for the computed Mesh.  Actual resolution may be less than this value.</param>
 /// <param name="_bakeCollider">Set to true if collider baking is/has been requested.</param>
 public SurfaceData(SurfaceId _id, MeshFilter _outputMesh, WorldAnchor _outputAnchor, MeshCollider _outputCollider, float _trianglesPerCubicMeter, bool _bakeCollider)
 {
     this.id = _id;
     this.outputMesh = _outputMesh;
     this.outputAnchor = _outputAnchor;
     this.outputCollider = _outputCollider;
     this.trianglesPerCubicMeter = _trianglesPerCubicMeter;
     this.bakeCollider = _bakeCollider;
 }
            public void DeleteWorldAnchor(TrackableIdPair trackableID)
            {
                // delete an existing world anchor
                if (mWorldAnchors.ContainsKey(trackableID))
                {
                    UnityEngine.VR.WSA.WorldAnchor wa = mWorldAnchors[trackableID];
                    mWorldAnchors.Remove(trackableID);

                    InternalDeleteWA(wa);
                }
            }
 /// <summary>
 /// <para>Adds a WorldAnchor to the batch with the specified identifier.</para>
 /// </summary>
 /// <param name="id">The identifier associated with this anchor in the batch. This must be unique per batch.</param>
 /// <param name="anchor">The anchor to add to the batch.</param>
 /// <returns>
 /// <para>Whether or not the anchor was added successfully.</para>
 /// </returns>
 public bool AddWorldAnchor(string id, WorldAnchor anchor)
 {
     if (string.IsNullOrEmpty(id))
     {
         throw new ArgumentException("id is null or empty!", "id");
     }
     if (anchor == null)
     {
         throw new ArgumentNullException("anchor");
     }
     return AddWorldAnchor_Internal(this.m_NativePtr, id, anchor);
 }
 private void OnWorldAnchorTrackingChanged(UnityEngine.VR.WSA.WorldAnchor wa, bool tracked)
 {
     if (mHoloLensTrackingCallback != null)
     {
         // translate from world anchor to trackable behaviour
         foreach (KeyValuePair <TrackableIdPair, UnityEngine.VR.WSA.WorldAnchor> worldAnchor in mWorldAnchors)
         {
             if (worldAnchor.Value == wa)
             {
                 mHoloLensTrackingCallback(worldAnchor.Key, tracked);
             }
         }
     }
 }
 private static void InvokeSurfaceDataReadyEvent(SurfaceDataReadyDelegate onDataReady, int surfaceId, MeshFilter outputMesh, WorldAnchor outputAnchor, MeshCollider outputCollider, float trisPerCubicMeter, bool bakeCollider, bool outputWritten, float elapsedBakeTimeSeconds)
 {
     if (onDataReady != null)
     {
         SurfaceData data;
         data.id.handle = surfaceId;
         data.outputMesh = outputMesh;
         data.outputAnchor = outputAnchor;
         data.outputCollider = outputCollider;
         data.trianglesPerCubicMeter = trisPerCubicMeter;
         data.bakeCollider = bakeCollider;
         onDataReady(data, outputWritten, elapsedBakeTimeSeconds);
     }
 }
 private static extern bool Internal_AddToWorkQueue(IntPtr observer, SurfaceDataReadyDelegate onDataReady, int surfaceId, MeshFilter filter, WorldAnchor wa, MeshCollider mc, float trisPerCubicMeter, bool createColliderData);
 /// <summary>
 /// <para>Saves the provided WorldAnchor with the provided identifier. If the identifier is already in use, the method will return false.</para>
 /// </summary>
 /// <param name="id">The identifier to save the anchor with. This needs to be unique for your app.</param>
 /// <param name="anchor">The anchor to save.</param>
 /// <returns>
 /// <para>Whether or not the save was successful. Will return false if the id conflicts with another already saved anchor's id.</para>
 /// </returns>
 public bool Save(string id, WorldAnchor anchor)
 {
     if (string.IsNullOrEmpty(id))
     {
         throw new ArgumentException("id must not be null or empty", "id");
     }
     if (anchor == null)
     {
         throw new ArgumentNullException("anchor");
     }
     return Save_Internal(this.m_NativePtr, id, anchor);
 }
Example #11
0
 private static extern bool INTERNAL_CALL_IsLocated_Internal(WorldAnchor self);
Example #12
0
 private bool IsLocated_Internal()
 {
     return(WorldAnchor.INTERNAL_CALL_IsLocated_Internal(this));
 }
Example #13
0
 private static extern void INTERNAL_CALL_GetSpatialAnchor_Internal(WorldAnchor self, out IntPtr value);
Example #14
0
 private static extern void INTERNAL_CALL_SetSpatialAnchor_Internal_FromScript(WorldAnchor self, IntPtr spatialAnchorPtr);
Example #15
0
 private void SetSpatialAnchor_Internal_FromScript(IntPtr spatialAnchorPtr)
 {
     WorldAnchor.INTERNAL_CALL_SetSpatialAnchor_Internal_FromScript(this, spatialAnchorPtr);
 }
 private static extern bool AddWorldAnchor_Internal(IntPtr context, string id, WorldAnchor anchor);
Example #17
0
 private static extern bool INTERNAL_CALL_IsLocated_Internal(WorldAnchor self);