HoloLens Development notes, hololens notes

Source: Internet
Author: User

HoloLens Development notes, hololens notes

The World Anchor space Anchor provides a way to retain an object at a specific position and in a rotating state. This ensures the stability of holographic objects and provides the ability to maintain the location of holographic objects in the real world. Simply put, you can add a space anchor for a holographic object, so that the holographic object can be accurately restored to its original position in subsequent steps.

 

WorldAnchor anchor = gameObject. AddComponent <WorldAnchor> ();

 

Removing a World Anchor remove a space Anchor  

If you no longer want to fix the GameObject in a specific location and do not want to move it in the scenario, you can call the Destroy () method to Destroy the WorldAnchor component, as shown below:

 

Destroy(gameObject.GetComponent<WorldAnchor>());

 

If you want to move objects in the scene immediately, you need to call DestroyImmediate () to destroy the space anchor component, as shown below:

 

DestroyImmediate(gameObject.GetComponent<WorldAnchor>());

 

Moving a World Anchored GameObject  

When a holographic object is attached with a space anchor, it cannot be moved. If you need a holographic object, you must:

DestroyImmediate(gameObject.GetComponent<WorldAnchor>());gameObject.transform.position = new Vector3(0, 0, 2);WorldAnchor anchor = gameObject.AddComponent<WorldAnchor>();

 

Handling Locatability Changes  

At a certain point in time, space anchors may not be located in the world. If this happens, Unity cannot update the position of the anchored object. This may change when the application is running. If you cannot promptly process changes in the positioning capability, the object may not appear in an accurate position.

In order to track changes in the ability to be located, the following actions must be taken:

 

Subscribe to events

The Code is as follows:

 

anchor.OnTrackingChanged += Anchor_OnTrackingChanged;

 

Handle OnTrackingChanged events

The Code is as follows:

Private void Anchor_OnTrackingChanged (WorldAnchor self, bool located) {// display or hide the object self. gameObject. SetActiveRecursively (located) based on the positioning status );}

 

Set a clear initial status

Sometimes space anchors can be located immediately. At this time, after a space anchor is added to an object, the isLocated attribute value of the Space anchor component is set to true, which means the OnTrackingChanged event will not be triggered. Therefore, we recommend that you use the initial isLocated status to call the OnTrackingChanged event immediately after adding the space anchor component, as shown below:

 

Anchor_OnTrackingChanged(anchor, anchor.isLocated);

 

Related Article

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.