问题
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