美文网首页
基于ARFoundation的AR应用获取Tracking状态

基于ARFoundation的AR应用获取Tracking状态

作者: 时空海带 | 来源:发表于2020-11-11 05:43 被阅读0次

    AR应用时常需要根据tracking状态做出响应,比如在跟踪丢失的时候提示用户从新进行定位。这就需要AR工程内提供一个专门负责跟踪tracking状态的类。通过 ARFoundation提供的ARSession类可以获取到跟踪的状态

    废话不多说,直接上代码:

    using UnityEngine;
    using UnityEngine.XR.ARFoundation;
    using UnityEngine.XR.ARSubsystems;
    
    public class ARStatusManager : MonoBehaviour
    {
        
        private void OnEnable()
        {
            ARSession.stateChanged += OnStateChanged;
        }
        private void OnDisable()
        {
            ARSession.stateChanged -= OnStateChanged;
        }
    
        private void OnStateChanged(ARSessionStateChangedEventArgs args)
        {
            switch (args.state)
            {
                case ARSessionState.None:
                    break;
                case ARSessionState.CheckingAvailability:
                    break;
                case ARSessionState.Installing:
                    break;
                case ARSessionState.NeedsInstall:
                    break;
                case ARSessionState.Ready:
                    break;
                case ARSessionState.SessionInitializing:
                    break;
                case ARSessionState.SessionTracking:
                    break;
                case ARSessionState.Unsupported:
                    break;
            }
    
            switch (ARSession.notTrackingReason)
            {
                case NotTrackingReason.None:
                    break;
                case NotTrackingReason.Initializing:
                    break;
                case NotTrackingReason.Relocalizing:
                    break;
                case NotTrackingReason.InsufficientLight:
                    break;
                case NotTrackingReason.InsufficientFeatures:
                    break;
                case NotTrackingReason.ExcessiveMotion:
                    break;
                case NotTrackingReason.Unsupported:
                    break;
            }
        }
    
    }
    

    相关文章

      网友评论

          本文标题:基于ARFoundation的AR应用获取Tracking状态

          本文链接:https://www.haomeiwen.com/subject/mrisbktx.html