/// <inheritdoc />
        public Transform ShowDefaultProgressIndicator()
        {
            CreateDefaultProgressIndicator();

            switch (defaultProgressIndicator.State)
            {
            case ProgressIndicatorState.Open:
            case ProgressIndicatorState.Opening:
                // If it's already open / opening, don't botheer to open again
                break;

            case ProgressIndicatorState.Closed:
                // Open it now - don't await result, we want to return the transform promptly
                defaultProgressIndicator.OpenAsync();
                break;

            case ProgressIndicatorState.Closing:
            default:
                // Open it now - don't await result, we want to return the transform promptly
                defaultProgressIndicator.OpenAsync();
                break;
            }

            return(defaultProgressIndicator.MainTransform);
        }
        private async Task TestOpenCloseProgressIndicatorAsync(GameObject progressIndicatorObject, IProgressIndicator progressIndicator, float timeOpen = 2f)
        {
            // Deactivate the progress indicator
            progressIndicatorObject.SetActive(false);

            // Make sure it's closed
            Assert.True(progressIndicator.State == ProgressIndicatorState.Closed, "Progress indicator was not in correct state on startup: " + progressIndicator.State);

            // Make sure we can set progress and message
            progressIndicator.Progress = 0;
            progressIndicator.Message  = "Progress Test";

            // Wait for it to open
            await progressIndicator.OpenAsync();

            // Make sure it's actually open
            Assert.True(progressIndicator.State == ProgressIndicatorState.Open, "Progress indicator was not open after open async call: " + progressIndicator.State);

            // Make sure we can set its progress and message while open
            // Also make sure we can set progress to a value greater than 1 without blowing anything up
            float timeStarted = Time.time;

            while (Time.time < timeStarted + timeOpen)
            {
                progressIndicator.Progress = Time.time - timeStarted;
                progressIndicator.Message  = "Current Time: " + Time.time;
                await Task.Yield();
            }

            // Wait for it to close
            await progressIndicator.CloseAsync();

            // Make sure it's actually closed
            Assert.True(progressIndicator.State == ProgressIndicatorState.Closed, "Progress indicator was not closed after close async call: " + progressIndicator.State);
        }
        private async void OpenProgressIndicator(IProgressIndicator indicator)
        {
            await indicator.OpenAsync();

            float timeStarted = Time.time;

            while (Time.time < timeStarted + loadingTime)
            {
                float normalizedProgress = Mathf.Clamp01((Time.time - timeStarted) / loadingTime);
                indicator.Progress = normalizedProgress;
                indicator.Message  = loadingMessages[Mathf.FloorToInt(normalizedProgress * loadingMessages.Length)];

                await Task.Yield();

                switch (indicator.State)
                {
                case ProgressIndicatorState.Open:
                    break;

                default:
                    // The indicator was closed
                    return;
                }
            }

            await indicator.CloseAsync();
        }
Exemplo n.º 4
0
    /// <summary>
    /// Animates the rotating orbs progress indicator.
    /// </summary>
    private async void UpdateProgressIndicator()
    {
        await indicator.OpenAsync();

        float timeStarted = Time.time;

        while (Time.time < timeStarted + 2f)
        {
            float normalizedProgress = Mathf.Clamp01((Time.time - timeStarted) / 2f);
            indicator.Progress = normalizedProgress;

            await Task.Yield();

            switch (indicator.State)
            {
            case ProgressIndicatorState.Open:
                break;

            default:
                // The indicator was closed.
                return;
            }
        }

        await indicator.CloseAsync();
    }
Exemplo n.º 5
0
    private async void OpenProgressIndicator(IProgressIndicator indicator)
    {
        await indicator.AwaitTransitionAsync();

        if (indicator.State == ProgressIndicatorState.Closed)
        {
            await indicator.OpenAsync();
        }
    }
Exemplo n.º 6
0
    // async task to display the progress of the indicator. See MRTK documentation on progress indicators for more details.
    private async void OpenProgressIndicator(IProgressIndicator indicator)
    {
        await indicator.OpenAsync();

        while (doIndicate)
        {
            progressIndicator.Progress = progress;
            await Task.Yield();
        }
        await indicator.CloseAsync();
    }
        public async void StartProgressBehavior()
        {
            if (startedProgressBehavior)
            {
                Debug.Log("Can't start until behavior is completed.");
                return;
            }

            startedProgressBehavior = true;

            IProgressIndicator indicator = progressIndicatorObject.GetComponent <IProgressIndicator>();

            indicator.Message = "Preparing for scene operation...";
            await indicator.OpenAsync();

            Task   sceneTask;
            string progressMessage;

            // A scene this small will load almost instantly, so we're doing a delay so the indicator is visible
            float timeStarted = Time.time;

            while (Time.time < timeStarted + loadDelay)
            {
                await Task.Yield();
            }

            if (CoreServices.SceneSystem.IsContentLoaded(sceneToLoad.Name))
            {
                sceneTask       = CoreServices.SceneSystem.UnloadContent(sceneToLoad.Name);
                progressMessage = "Unloading scene {0}";
            }
            else
            {
                sceneTask       = CoreServices.SceneSystem.LoadContent(sceneToLoad.Name, UnityEngine.SceneManagement.LoadSceneMode.Additive);
                progressMessage = "Loading scene {0}";
            }

            indicator.Message = progressMessage;

            while (!sceneTask.IsCompleted)
            {
                indicator.Message = string.Format(progressMessage, CoreServices.SceneSystem.SceneOperationProgress * 100);
                await Task.Yield();
            }

            indicator.Message = "Finished operation";
            await indicator.CloseAsync();

            startedProgressBehavior = false;
        }
Exemplo n.º 8
0
        public async void StartProgressBehavior()
        {
            if (progressIndicator.State != ProgressIndicatorState.Closed)
            {
                Debug.LogWarning("Can't start progress behavior in this state.");
                return;
            }

            progressIndicator.Message  = $"Starting animation...";
            progressIndicator.Progress = 0;
            await progressIndicator.OpenAsync();

            animator.SetTrigger("PlayAnimation");

            await Task.Yield();

            // Wait for animation to START playing
            bool playingAnimation = false;

            while (!playingAnimation)
            {
                var stateInfo = animator.GetCurrentAnimatorStateInfo(0);
                playingAnimation = stateInfo.IsName(animationName);

                progressIndicator.Message = $"Waiting for animation to start...";
                await Task.Yield();
            }

            // Wait for animation to STOP playing
            while (playingAnimation)
            {
                var stateInfo = animator.GetCurrentAnimatorStateInfo(0);
                playingAnimation = stateInfo.IsName(animationName);

                if (playingAnimation)
                {
                    progressIndicator.Message  = $"Waiting for animation to finish...";
                    progressIndicator.Progress = stateInfo.normalizedTime;
                }
                await Task.Yield();
            }

            progressIndicator.Progress = 1;
            progressIndicator.Message  = $"Finished with animation...";

            await progressIndicator.CloseAsync();
        }
Exemplo n.º 9
0
    private async void ToggleIndicator(IProgressIndicator indicator)
    {
        // If the indicator is opening or closing, wait for that to finish before trying to open / close it
        // Otherwise the indicator will display an error and take no action
        await indicator.AwaitTransitionAsync();

        switch (indicator.State)
        {
        case ProgressIndicatorState.Closed:
            await indicator.OpenAsync();

            break;

        case ProgressIndicatorState.Open:
            await indicator.CloseAsync();

            break;
        }
    }
Exemplo n.º 10
0
        public async void StartProgressBehavior()
        {
            if (tokenSource != null)
            {
                Debug.LogWarning("Can't start progress behavior in this state.");
                return;
            }

            progressIndicator.Message = "Opening...";
            await progressIndicator.OpenAsync();

            tokenSource = new CancellationTokenSource();
            Task asyncMethod = AsyncMethod(tokenSource.Token);

            progressIndicator.Message = "Waiting for async method to complete...";
            while (!asyncMethod.IsCompleted)
            {
                await Task.Yield();
            }
            tokenSource = null;

            progressIndicator.Message = "Closing...";
            await progressIndicator.CloseAsync();
        }
        /// <inheritdoc />
        public async Task DoSceneTransition(IEnumerable <Func <Task> > sceneOperations, IProgressIndicator progressIndicator = null)
        {
            if (TransitionInProgress)
            {
                throw new Exception("Attempting to do a transition while one is already in progress.");
            }

            #region Transition begin

            TransitionInProgress = true;
            OnTransitionStarted?.Invoke();

            if (progressIndicator == null && sceneTransitionServiceProfile.UseDefaultProgressIndicator)
            {   // If we haven't been given a progress indicator, and we're supposed to use a default
                // find / create the default progress indicator
                CreateDefaultProgressIndicator();
                progressIndicator = defaultProgressIndicator;
            }

            if (UseFadeColor)
            {
                await FadeOut();
            }

            if (progressIndicator != null)
            {
                await progressIndicator.OpenAsync();
            }

            #endregion

            #region Task execution

            // Make sure we're on the main thread

            foreach (Func <Task> sceneOperation in sceneOperations)
            {
                await sceneOperation();
            }

            #endregion

            #region Transition end

            // If we used a progress indicator, close it
            if (progressIndicator != null)
            {
                await progressIndicator.CloseAsync();
            }


            if (UseFadeColor)
            {
                await FadeIn();
            }

            TransitionInProgress = false;
            OnTransitionCompleted?.Invoke();

            #endregion
        }