HoloLens Development notes-unity world anchor Space anchor

Source: Internet
Author: User

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:

    1. Immediately destroy the space anchor Assembly
    2. Moving holographic objects
    3. 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:

    1. Subscribe to ontrackingchanged Events
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.