/// <inheritdoc/>
        public async Task CloseAsync()
        {
            if (closeCurve.length == 0)
            {
                Debug.LogWarning("Open curve length is zero - this may result in an infinite loop.");
            }

            float minScale = closeCurve.Evaluate(Mathf.Infinity);

            if (minScale > 0)
            {
                Debug.LogWarning("Open curve value never reaches 0 - this may result in an infinite loop.");
            }

            if (state != ProgressIndicatorState.Open)
            {
                throw new System.Exception("Can't close in state " + state);
            }

            state = ProgressIndicatorState.Closing;

            float startTime  = Time.unscaledTime;
            float closeScale = 1f;

            while (closeScale > 0)
            {
                closeScale = closeCurve.Evaluate(Time.unscaledTime - startTime);
                scaleTargetObject.transform.localScale = Vector3.one * currentScale * closeScale;
                await Task.Yield();
            }

            state = ProgressIndicatorState.Closed;

            gameObject.SetActive(false);
        }
        /// <inheritdoc/>
        public void CloseImmediate()
        {
            if (state != ProgressIndicatorState.Open)
            {
                throw new System.Exception("Can't close in state " + state);
            }

            state = ProgressIndicatorState.Closed;
            gameObject.SetActive(false);
        }
Example #3
0
        /// <summary>
        /// If the percent value is an invalid percentage (less than 0 or more than 100)
        /// the returned string is a moving star...
        /// </summary>
        public static string GetProgressBar(int percent, ref ProgressIndicatorState progressIndicator)
        {
            const int     baseLength = 50;
            const int     fullLength = 52;
            StringBuilder dots       = new StringBuilder();

            if (percent < 0 || percent > 100)
            {
                if (progressIndicator == null)
                {
                    progressIndicator = new ProgressIndicatorState();
                }
                dots.Append("[");
                for (int i = 0; i < progressIndicator.MovingIndicatorPosition; i++)
                {
                    dots.Append(" ");
                }
                dots.Append('*');
                // take account of the star and the bracket
                for (int i = progressIndicator.MovingIndicatorPosition + 2; i < baseLength + 2; i++)
                {
                    dots.Append(" ");
                }
                dots.Append("]");
                progressIndicator.MovingIndicatorPosition += progressIndicator.DirectionIsRight ? 1 : -1;
                if (progressIndicator.MovingIndicatorPosition >= baseLength || progressIndicator.MovingIndicatorPosition <= 0)
                {
                    progressIndicator.DirectionIsRight = !progressIndicator.DirectionIsRight;
                }
                return(dots.ToString());
            }
            else
            {
                int percentByTwo = (int)Math.Max(0, Math.Min(Math.Floor(percent / 2f), baseLength));
                dots.Append("[");
                for (int i = 1; i <= percentByTwo; i++)
                {
                    dots.Append(".");
                }
                for (int i = percentByTwo; i < baseLength; i++)
                {
                    dots.Append(" ");
                }
                dots.Append("]");
                string percentage = $"{percent}%";
                int    halves     = (fullLength / 2) - percentage.Length / 2;
                int    alignRight = percentage.Length % 2;
                return(dots.ToString(0, halves) + percentage + dots.ToString(fullLength - halves + alignRight, halves - alignRight));
            }
        }
        /// <inheritdoc/>
        public async Task CloseAsync()
        {
            if (state != ProgressIndicatorState.Open)
            {
                throw new System.Exception("Can't close in state " + state);
            }

            state = ProgressIndicatorState.Closing;

            await Task.Yield();

            state = ProgressIndicatorState.Closed;

            gameObject.SetActive(false);
        }
        /// <inheritdoc/>
        public async Task OpenAsync()
        {
            if (state != ProgressIndicatorState.Closed)
            {
                throw new System.Exception("Can't open in state " + state);
            }

            gameObject.SetActive(true);

            state = ProgressIndicatorState.Opening;

            await Task.Yield();

            state = ProgressIndicatorState.Open;
        }
        /// <inheritdoc/>
        public async Task OpenAsync()
        {
            if (state != ProgressIndicatorState.Closed)
            {
                throw new System.Exception("Can't open in state " + state);
            }

            smoothProgress     = 0;
            lastSmoothProgress = 0;
            progressText.text  = string.Format(progressStringFormat, smoothProgress);

            gameObject.SetActive(true);

            state = ProgressIndicatorState.Opening;

            await Task.Yield();

            state = ProgressIndicatorState.Open;
        }
Example #7
0
        /// <inheritdoc/>
        public async Task CloseAsync()
        {
            if (state != ProgressIndicatorState.Open)
            {
                throw new System.Exception("Can't close in state " + state);
            }

            state = ProgressIndicatorState.Closing;

            StopOrbs();

            while (!hasAnimationFinished && isActiveAndEnabled)
            {
                await Task.Yield();
            }

            state = ProgressIndicatorState.Closed;
            gameObject.SetActive(false);
        }
Example #8
0
        /// <inheritdoc/>
        public void CloseImmediate()
        {
            if (closeCurve.length == 0)
            {
                Debug.LogWarning("Open curve length is zero - this may result in an infinite loop.");
            }

            float minScale = closeCurve.Evaluate(Mathf.Infinity);

            if (minScale > 0)
            {
                Debug.LogWarning("Open curve value never reaches 0 - this may result in an infinite loop.");
            }

            if (state != ProgressIndicatorState.Open)
            {
                throw new System.Exception("Can't close in state " + state);
            }

            scaleTargetObject.transform.localScale = Vector3.zero;
            state = ProgressIndicatorState.Closed;
            gameObject.SetActive(false);
        }
        /// <inheritdoc/>
        public async Task OpenAsync()
        {
            if (openCurve.length == 0)
            {
                Debug.LogWarning("Open curve length is zero - this may result in an infinite loop.");
            }

            float maxScale = openCurve.Evaluate(Mathf.Infinity);

            if (maxScale < 1f)
            {
                Debug.LogWarning("Open curve value never reaches 1 - this may result in an infinite loop.");
            }

            if (state != ProgressIndicatorState.Closed)
            {
                throw new System.Exception("Can't open in state " + state);
            }

            gameObject.SetActive(true);

            Reset();

            state = ProgressIndicatorState.Opening;

            float startTime = Time.unscaledTime;
            float openScale = 0f;

            while (openScale < 1)
            {
                openScale = openCurve.Evaluate(Time.unscaledTime - startTime);
                scaleTargetObject.transform.localScale = Vector3.one * currentScale * openScale;
                await Task.Yield();
            }

            state = ProgressIndicatorState.Open;
        }