Ejemplo n.º 1
0
    public static bool IsUpAndRunning(this ARSessionState state)
    {
#if UNITY_EDITOR
        return(Input.GetKey(KeyCode.A));
#endif
        return(state == ARSessionState.Ready || state == ARSessionState.SessionTracking || state == ARSessionState.SessionInitializing);
    }
        private void ARSessionOnStateChanged(ARSessionStateChangedEventArgs args)
        {
            infoString = args.state.ToInfoString();

            Logger.LogFromMethod("ARFoundationSessionManager", "ARSessionOnStateChanged", infoString, DebugMode);

            if (args.state == ARSessionState.SessionTracking)
            {
                if (!trackingStarted)
                {
                    trackingStarted = true;
                    Logger.LogFromMethod("ARFoundationSessionManager", "ARSessionOnStateChanged", "Tracking Started!.", DebugMode);
                    trackingStartedCallback?.Invoke();
                }
                else if (currentStatus != ARSessionState.SessionTracking)
                {
                    Logger.LogFromMethod("ARFoundationSessionManager", "ARSessionOnStateChanged", "Tracking Restored!", DebugMode);
                    trackingRestoredCallback?.Invoke();
                }

                if (onAfterReset != null)
                {
                    Logger.LogFromMethod("ARFoundationSessionManager", "ARSessionOnStateChanged", "Emitting 'OnAfterReset' event.", DebugMode);
                    onAfterReset.Invoke();
                    onAfterReset = null;
                }
            }
            else if (currentStatus == ARSessionState.SessionTracking)
            {
                Logger.LogFromMethod("ARFoundationSessionManager", "ARSessionOnStateChanged", "Tracking Lost!", DebugMode);
                trackingLostCallback?.Invoke();
            }

            currentStatus = args.state;
        }
    public static string ToInfoString(this ARSessionState state)
    {
        switch (state)
        {
        case ARSessionState.None:
            return("None");

        case ARSessionState.Unsupported:
            return("Unsupported");

        case ARSessionState.CheckingAvailability:
            return("CheckingAvailability");

        case ARSessionState.NeedsInstall:
            return("NeedsInstall");

        case ARSessionState.Installing:
            return("Installing");

        case ARSessionState.Ready:
            return("Ready");

        case ARSessionState.SessionInitializing:
            return("SessionInitializing");

        case ARSessionState.SessionTracking:
            return("SessionTracking");

        default:
            return("None");
        }
    }
Ejemplo n.º 4
0
        private void OnARSessionStateChanged(ARSessionState arSessionState)
        {
            switch (arSessionState)
            {
            case ARSessionState.None:
            case ARSessionState.Unsupported:
            case ARSessionState.CheckingAvailability:
            case ARSessionState.NeedsInstall:
            case ARSessionState.Installing:
            case ARSessionState.Ready:
                SetLessonARState(ARLessonState.NotRunning);
                break;

            case ARSessionState.SessionInitializing:
                SetLessonARState(ARLessonState.ExtractingFeaturePoints);
                break;

            case ARSessionState.SessionTracking:
                // if we were extracting feature points or were not running, we need to place lesson
                // if we were placing or running, we should continue do the same
                if (m_ARLessonState == ARLessonState.ExtractingFeaturePoints || m_ARLessonState == ARLessonState.NotRunning)
                {
                    SetLessonARState(ARLessonState.PlacingLesson);
                }
                break;
            }
        }
Ejemplo n.º 5
0
        protected override void OnDisable()
        {
            base.OnDisable();

            // Only set back to ready if we were previously running
            if (state > ARSessionState.Ready)
            {
                state = ARSessionState.Ready;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Begin installing AR software on the current device (if supported).
        /// </summary>
        /// <remarks>
        /// <para>
        /// Installation may be asynchronous, so this is implemented as a coroutine.
        /// It is safe to call this multiple times, but you must first call <see cref="CheckAvailability"/>.
        /// </para><para>
        /// You must call <see cref="CheckAvailability"/> before tring to Install
        /// and the <see cref="systemState"/> must not be <see cref="ARSystemState.Unsupported"/>
        /// or this method will throw.
        /// </para>
        /// </remarks>
        /// <returns>An <c>IEnumerator</c> used for a coroutine.</returns>
        public static IEnumerator Install()
        {
            while ((state == ARSessionState.Installing) || (state == ARSessionState.CheckingAvailability))
            {
                yield return(null);
            }

            switch (state)
            {
            case ARSessionState.Installing:
            case ARSessionState.NeedsInstall:
                break;

            case ARSessionState.None:
                throw new InvalidOperationException("Cannot install until availability has been determined. Have you called CheckAvailability()?");

            case ARSessionState.Ready:
            case ARSessionState.SessionInitializing:
            case ARSessionState.SessionTracking:
                yield break;

            case ARSessionState.Unsupported:
                throw new InvalidOperationException("Cannot install because XR is not supported on this platform.");
            }

            // We can't get this far without having had a valid subsystem at one point.
            if (s_Instance.subsystem == null)
            {
                throw new InvalidOperationException("The subsystem was destroyed while attempting to install AR software.");
            }

            state = ARSessionState.Installing;
            var installPromise = s_Instance.subsystem.InstallAsync();

            yield return(installPromise);

            var installStatus = installPromise.result;

            switch (installStatus)
            {
            case SessionInstallationStatus.Success:
                state          = ARSessionState.Ready;
                s_Availability = (s_Availability | SessionAvailability.Installed);
                break;

            case SessionInstallationStatus.ErrorUserDeclined:
                state = ARSessionState.NeedsInstall;
                break;

            default:
                state = ARSessionState.Unsupported;
                break;
            }
        }
Ejemplo n.º 7
0
        private void CheckTrackingState(ARSessionState newState)
        {
            isTracking = newState == ARSessionState.SessionTracking;

            if (!isTracking)
            {
                foreach (KeyValuePair <Transform, SpaceContainer> item in ARSpace.transformToSpace)
                {
                    item.Value.filter.InvalidateHistory();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Resets the AR Session. This destroys the current session, including all trackables, and
        /// then establishes a new session.
        /// </summary>
        public void Reset()
        {
            if (subsystem != null)
            {
                subsystem.Reset();
            }

            if (state > ARSessionState.Ready)
            {
                state = ARSessionState.SessionInitializing;
            }
        }
Ejemplo n.º 9
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            // Only set back to ready if we were previously running
            if (state > ARSessionState.Ready)
            {
                state = ARSessionState.Ready;
            }

            s_Instance = null;
        }
Ejemplo n.º 10
0
        public IEnumerator CheckAvailability()
        {
            while (state == ARSessionState.CheckingAvailability)
            {
                yield return(null);
            }
            if (state != ARSessionState.None)
            {
                yield break;
            }
            var subsystem = GetSubsystem();

            if (subsystem == null)
            {
                state = ARSessionState.Unsupported;
            }
            else if (state == ARSessionState.None)
            {
                Txt3.text = "check";
                state     = ARSessionState.CheckingAvailability;
                var availabilityPromise = subsystem.GetAvailabilityAsync();
                yield return(availabilityPromise);

                Txt4.text = "promisse";

                s_Availability = availabilityPromise.result;
                if (s_Availability.IsSupported() && s_Availability.IsInstalled())
                {
                    state = ARSessionState.Ready;
                }
                else if (s_Availability.IsSupported() && !s_Availability.IsInstalled())
                {
                    Txt5.text = "install";
                    bool supportsInstall =
                        subsystem.subsystemDescriptor.supportsInstall;
                    state = supportsInstall ? ARSessionState.NeedsInstall : ARSessionState.Unsupported;
                }
                else
                {
                    Txt6.text = "unsupp";

                    state = ARSessionState.Unsupported;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Start checking the availability of XR on the current device.
        /// </summary>
        /// <remarks>
        /// The availability check may be asynchronous, so this is implemented as a coroutine.
        /// It is safe to call this multiple times; if called a second time while an availability
        /// check is being made, it returns a new coroutine which waits on the first.
        /// </remarks>
        /// <returns>An <c>IEnumerator</c> used for a coroutine.</returns>
        public static IEnumerator CheckAvailability()
        {
            // Wait if availability is currently being checked.
            while (state == ARSessionState.CheckingAvailability)
            {
                yield return(null);
            }

            // Availability has already been determined if we make it here and the state is not None.
            if (state != ARSessionState.None)
            {
                yield break;
            }

            // Normally, the subsystem is created in OnEnable, but users may
            // want to check availability before enabling the session.
            s_Instance.CreateSubsystemIfNecessary();

            if (s_Instance.subsystem == null)
            {
                // No subsystem means there is no support on this platform.
                state = ARSessionState.Unsupported;
            }
            else if (state == ARSessionState.None)
            {
                state = ARSessionState.CheckingAvailability;
                var availabilityPromise = s_Instance.subsystem.GetAvailabilityAsync();
                yield return(availabilityPromise);

                s_Availability = availabilityPromise.result;

                if (s_Availability.IsSupported() && s_Availability.IsInstalled())
                {
                    state = ARSessionState.Ready;
                }
                else if (s_Availability.IsSupported() && !s_Availability.IsInstalled())
                {
                    state = s_Instance.subsystem.SubsystemDescriptor.supportsInstall ? ARSessionState.NeedsInstall : ARSessionState.Unsupported;
                }
                else
                {
                    state = ARSessionState.Unsupported;
                }
            }
        }
Ejemplo n.º 12
0
        void Update()
        {
            if (subsystem != null && subsystem.running)
            {
                subsystem.Update(new XRSessionUpdateParams
                {
                    screenOrientation = Screen.orientation,
                    screenDimensions  = new Vector2Int(Screen.width, Screen.height)
                });

                switch (subsystem.trackingState)
                {
                case TrackingState.None:
                case TrackingState.Limited:
                    state = ARSessionState.SessionInitializing;
                    break;

                case TrackingState.Tracking:
                    state = ARSessionState.SessionTracking;
                    break;
                }
            }
        }
 /// <summary>
 /// Constructor for these event arguments.
 /// </summary>
 /// <param name="state">The new session state.</param>
 public ARSessionStateChangedEventArgs(ARSessionState state)
 {
     this.state = state;
 }