The World Anchor space Anchor provides a way to keep an object in a specific position and in a rotational state. This ensures the stability of the holographic object while providing the ability to maintain the location of the holographic object in the real world. Simply put, you can add a space anchor to a holographic object so that the holographic object can be restored exactly to its original position in the next steps.
Adding a World Anchor add space anchor
Namespaces: UnityEngine.VR.WSA
Type: worldanchor
The way to add a space anchor in unity is simple, as follows:
Worldanchor anchor = gameobject.addcomponent<worldanchor> ();
Removing a world Anchor remove space anchor
If you no longer want to fix the gameobject in a specific location and do not want to move it in the scene, you can call the Destroy () method to destroy the Worldanchor component, as follows:
Destroy (gameobject.getcomponent<worldanchor> ());
If you want to move the object immediately in the scene, you need to call Destroyimmediate () to destroy the space anchor component, as follows:
Destroyimmediate (gameobject.getcomponent<worldanchor> ());
Moving a world anchored gameobject moving anchored holographic object
When a holographic object has been attached to a space anchor component, it cannot be moved. If you need a certain holographic object, then you have to do this:
- Immediately destroy the space anchor Assembly
- Moving holographic objects
- Add a new space anchor to the holographic object
Destroyimmediate (gameobject.getcomponent<worldanchor>new Vector3 (00 2 = gameobject.addcomponent<worldanchor> ();
The change of handling locatability changes processing ability of localization
At some point in time, the space anchor may not be able to be located in the world. If this happens, unity will not be able to update the location of the anchored object. This can also change when the app is running. Inability to deal with changes in the ability to localize in a timely manner may result in the object not appearing in an accurate position.
In order to track changes in the ability to localize, the following practices need to be taken:
- Subscribe to ontrackingchanged Events
- Handle this event
Subscribe to Events
The code is as follows:
Anchor. Ontrackingchanged + = anchor_ontrackingchanged;
Handling Ontrackingchanged Events
The code is as follows:
Private void BOOL located) { // self.gameObject.SetActiveRecursively (located) for simple display or hidden objects based on the positioning state ;}
Set a definite initial state
Sometimes a space anchor can be positioned immediately. At this point, after adding a spatial anchor to the object, the Islocated property value of the spatial anchor component will be set to true, which is the Ontrackingchanged event will not be triggered. Therefore, after adding the spatial anchor component, it is recommended to use the initial islocated state immediately to invoke the Ontrackingchanged event, as follows:
Anchor_ontrackingchanged (Anchor, anchor.islocated);
HoloLens Development notes-unity world anchor Space anchor