//================================================================================================================================ // // Copyright (c) 2015-2021 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved. // EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China // and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd. // //================================================================================================================================ using System; using UnityEngine; namespace easyar { /// /// which controls the world root in the scene. /// The world root is a virtual node, representing the relative node when the camera moves in a motion tracking system. It will be automatically generated to be the origin of the global coordinate system when needed if not manually set in the scene. /// 在场景中控制世界根节点的 /// 世界根节点是一个虚拟的节点,它表示在运动跟踪的系统中,camera移动的相对节点。如果场景中没有手动设置这个节点,它将在被需要的时候自动被设置为全局坐标系的原点。 /// public class WorldRootController : MonoBehaviour { /// /// Strategy to control the . If you are willing to control or there are other components controlling , make sure to set it to . /// 的控制策略。如果你打算自己控制或是有其它组件在控制,需要设为 /// public ActiveControlStrategy ActiveControl; private bool trackingStarted; /// /// Motion tracking status change event. /// 跟踪状态改变的事件。 /// public event Action TrackingStatusChanged; /// /// Strategy to control the . /// 的控制策略。 /// public enum ActiveControlStrategy { /// /// Active is false when the motion tracking status is not tracking, true otherwise. /// 当运动跟踪状态是未跟踪时Active为false,其它情况Active为true。 /// HideWhenNotTracking, /// /// False before the motion tracking status turns to a tracking status, then true. /// 在运动跟踪状态第一次不是未跟踪前Active为false,之后为true。 /// HideBeforeTrackingStart, /// /// Do not control . /// 不控制 /// None, } /// /// Motion tracking status at the moment. /// 当前运动跟踪状态。 /// public MotionTrackingStatus TrackingStatus { get; private set; } /// /// MonoBehaviour Start /// protected virtual void Start() { if (TrackingStatus == MotionTrackingStatus.NotTracking && (ActiveControl == ActiveControlStrategy.HideBeforeTrackingStart || ActiveControl == ActiveControlStrategy.HideWhenNotTracking)) { gameObject.SetActive(false); } } /// /// Usually only for internal assemble use. Process tracking event. /// 通常只在内部组装时使用。处理跟踪事件。 /// internal void OnTracking(MotionTrackingStatus status) { if (TrackingStatus != status) { if (ActiveControl == ActiveControlStrategy.HideWhenNotTracking || (ActiveControl == ActiveControlStrategy.HideBeforeTrackingStart && !trackingStarted)) { gameObject.SetActive(!(status == MotionTrackingStatus.NotTracking)); } if (!trackingStarted && status != MotionTrackingStatus.NotTracking) { trackingStarted = true; } if (TrackingStatusChanged != null) { TrackingStatusChanged(status); } TrackingStatus = status; } } } }