In UnityARWorldMap, How will the user know if the GameObjects are Relocalized?

大城市里の小女人 提交于 2020-01-04 05:05:16

问题


I have tested the scene UnityARWorldMap.I have successfully relocalized ARworldmap.Once the models/Gameobjects are relocalized I want the tracking and detected planes to disappear.I found a class called UpdateWorldMappingStatus.cs .I tried to add some code similar to CheckWorldMapStatus method that is I added function CheckIfRelocalized method.Below is the given code.

public class UpdateWorldMappingStatus : MonoBehaviour 
{
    public Text text;
    public Text tracking;

    // Use this for initialization
    void Start () 
    {
        UnityARSessionNativeInterface.ARFrameUpdatedEvent += CheckWorldMapStatus;

        // I have subscibed to a event
        UnityARSessionNativeInterface.ARFrameUpdatedEvent += CheckIfRelocalized;
    }

    void CheckWorldMapStatus(UnityARCamera cam)
    {
        text.text = cam.worldMappingStatus.ToString ();
        tracking.text = cam.trackingState.ToString () + " " + cam.trackingReason.ToString ();
    }

    void CheckIfRelocalized(UnityARCamera cam)
    {
        if (cam.worldMappingStatus==ARWorldMappingStatus.ARWorldMappingStatusMapped &&cam.trackingState == ARTrackingState.ARTrackingStateNormal && cam.trackingReason==ARTrackingStateReason.ARTrackingStateReasonNone)
        {
            Debug.Log("Plane Detection Stopped");
            StopPlaneDetection();
        }
    }

    void OnDestroy()
    {
        UnityARSessionNativeInterface.ARFrameUpdatedEvent -= CheckWorldMapStatus;
        UnityARSessionNativeInterface.ARFrameUpdatedEvent -= CheckIfRelocalized;
    }

    public void StopPlaneDetection()
    {
        UnityARSessionNativeInterface session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
        ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
        config.planeDetection = UnityARPlaneDetection.None;
        config.enableLightEstimation = true;
        //config.enableAutoFocus = true;
        session.RunWithConfig(config);
    }
}

In the above code when I click load button the models immediately appear in front of the screen.But If I did not use the CheckIfRelocalized method the models relocalize in their initially set positions while saving but cannot hide the planes.

来源:https://stackoverflow.com/questions/55842300/in-unityarworldmap-how-will-the-user-know-if-the-gameobjects-are-relocalized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!