HoloLens Development Notes-Unity's persistence scene hold

Source: Internet
Author: User

Persistence scene hold is a key feature of the HoloLens holographic experience, when the user leaves the original scene, the holographic objects in the original scene will remain in a certain position, and when the user returns to the original scene, the holographic content of the original scene can be accurately restored. The Worldanchorstore class is the key API for implementing this feature, which ensures that users can paste any holographic object into any location they want to place.

How to persist holograms across sessions maintain holographic objects throughout the session

Worldanchorstore allows you to maintain the position of the space anchor in the scene, so that you can really keep the holographic object, you need to use a specific space anchor to track each object individually. Typically, a root gameobject is created with a space anchor attached, and a space anchor component with a relative position offset is attached to its sub-gameobject.

To load a holographic object from a previous scene:

    1. Get Worldanchorstore Object
    2. Loads the space anchor associated application data from which to get the spatial anchor ID
    3. Get the spatial anchor object by ID

Before the next scene, in order to save the holographic information:

    1. Get Worldanchorstore Object
    2. Specify the ID to hold the corresponding space anchor object
    3. Maintain application data associated with a spatial anchor

Getting the Worldanchorstore gets the Worldanchorstore object

Namespaces: UnityEngine.WSA.VR.Persistence

Type: worldanchorstore

In order to be able to use worldanchorstore later, we need to open this object through an asynchronous operation, as follows:

Worldanchorstore.getasync (storeloaded); Private void storeloaded (Worldanchorstore store) {       this. store = store;} 

You can now use the Worldanchorstore object to save the scene information.

Saving a Worldanchor save a space anchor

Note: The same spatial anchor cannot be saved multiple times. Each space anchor should be saved only once, if you need to update the space anchor information, you need to delete the old space anchor information, and then save the new space anchor information.

Private void savegame () {       //  Save the spatial anchor corresponding to the holographic object data       if (!  this//  only holds the root object once        {              this. Store. Save ("rootgameobject", anchor);              Assert (this. savedroot);}       }

Loading a worldanchor loads a space anchor

Loading spatial anchor data is simple, as follows:

Private void Loadgame () {       //  Save data about holograms positionedby this world anchor       this
    this. Store. Load ("rootgameobject", Rootgameobject);        if (!  This . Savedroot)       {              //  We did not successfully save the space anchor and holographic object data, we need to replace our object        }}

Enumerating Existing Anchors enumerate existing space anchors

We can find the previously saved space anchors by enumerating the saved space anchor information:

string  This . Store. Getallids ();  for (int0; index < IDs. Length; index++) {        Debug.Log (Ids[index]);}

HoloLens Development Notes-Unity's persistence scene hold

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.