[英]How to reset or restart the ARCore session?
我需要reset
/ restart
ARCore session。在 ARKit 中,我只需要创建一个新配置并执行RunWithConfigAndOptions
方法,但我找不到有关如何在 ARCore 中执行此操作的任何信息。 以下是我在 Unity 中用于 ARKit 的代码:
ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
config.planeDetection = UnityARPlaneDetection.Horizontal;
config.alignment = UnityARAlignment.UnityARAlignmentGravity;
config.enableLightEstimation = true;
UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(config,
UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors |
UnityARSessionRunOption.ARSessionRunOptionResetTracking);
我在 Unity 工作,但我想任何信息都会有用。
谢谢
尝试DestroyImmediate(session)
或Destroy(session)
。 其中之一可能会起作用。
ARCoreSession session = goARCoreDevice.GetComponent<ARCoreSession>();
ARCoreSessionConfig myConfig = session.SessionConfig;
DestroyImmediate(session);
// Destroy(session);
yield return null;
session = goARCoreDevice.AddComponent<ARCoreSession>();
session.SessionConfig = myConfig;
session.enabled = true;
希望这可以帮助。
要禁用 ARCore 会话,
GameObject.Find ("ARCore Device").GetComponent<ARCoreSession> ().enabled = false;
要重置 ARCore 会话,
//Resetting ARCoreSession
ARCoreSession session = GameObject.Find ("ARCore Device").GetComponent<ARCoreSession> ();
ARCoreSessionConfig myConfig = session.SessionConfig;
DestroyImmediate (session);
就我而言,我继承了一个 Unity3D ARCore 项目,设置有点奇怪。
在我的例子中,为了正确重置 session(否则它不会在场景加载时重新开始跟踪),最简单的解决方案是首先找到 ARCore Device 游戏对象并取消选中 Unity3D 编辑器中启用的脚本。
完成后,我只需要在 Awake() function 中找到 ARCoreSession(但您可能需要它在 Start() 中执行此操作,具体取决于您的项目是如何设置的,如果您有其他先决条件)然后简单地启用脚本
GoogleARCore.ARCoreSession g = GameObject.Find("ARCore Device").GetComponent<GoogleARCore.ARCoreSession>();
g.enabled = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.