Пример #1
0
        /// <summary>
        /// Updates the foreground bar's scale
        /// </summary>
        protected virtual void UpdateBars()
        {
            float newFill;
            float newFillDelayed;
            float t1, t2 = 0f;

            if (_direction < 0)
            {
                newFill = ComputeNewFill(LerpForegroundBar, LerpForegroundBarSpeedDecreasing, LerpForegroundBarDurationDecreasing, LerpForegroundBarCurveDecreasing, 0f, _percentLastTimeBarWasUpdated, out t1);
                SetBarInternal(newFill, ForegroundBar, _foregroundImage, _initialBarSize);
                SetBarInternal(newFill, DelayedBarIncreasing, _delayedIncreasingImage, _initialBarSize);

                BarProgress = newFill;
                DelayedBarIncreasingProgress = newFill;

                CurrentState = MMProgressBarStates.Decreasing;

                if (_time - _lastUpdateTimestamp > DecreasingDelay)
                {
                    newFillDelayed = ComputeNewFill(LerpDecreasingDelayedBar, LerpDecreasingDelayedBarSpeed, LerpDecreasingDelayedBarDuration, LerpDecreasingDelayedBarCurve, DecreasingDelay, _delayedBarDecreasingProgress, out t2);
                    SetBarInternal(newFillDelayed, DelayedBarDecreasing, _delayedDecreasingImage, _initialBarSize);

                    DelayedBarDecreasingProgress = newFillDelayed;
                    CurrentState = MMProgressBarStates.InDecreasingDelay;
                }
            }
            else
            {
                newFill = ComputeNewFill(LerpForegroundBar, LerpIncreasingDelayedBarSpeed, LerpIncreasingDelayedBarDuration, LerpIncreasingDelayedBarCurve, 0f, _delayedBarIncreasingProgress, out t1);
                SetBarInternal(newFill, DelayedBarIncreasing, _delayedIncreasingImage, _initialBarSize);

                DelayedBarIncreasingProgress = newFill;
                CurrentState = MMProgressBarStates.Increasing;

                if (_time - _lastUpdateTimestamp > IncreasingDelay)
                {
                    newFillDelayed = ComputeNewFill(LerpIncreasingDelayedBar, LerpForegroundBarSpeedIncreasing, LerpForegroundBarDurationIncreasing, LerpForegroundBarCurveIncreasing, IncreasingDelay, _delayedBarDecreasingProgress, out t2);

                    SetBarInternal(newFillDelayed, DelayedBarDecreasing, _delayedDecreasingImage, _initialBarSize);
                    SetBarInternal(newFillDelayed, ForegroundBar, _foregroundImage, _initialBarSize);

                    BarProgress = newFillDelayed;
                    DelayedBarDecreasingProgress = newFillDelayed;
                    CurrentState = MMProgressBarStates.InDecreasingDelay;
                }
            }

            if ((t1 >= 1f) && (t2 >= 1f))
            {
                _coroutineShouldRun = false;
                if (_direction > 0)
                {
                    OnBarMovementIncreasingStop?.Invoke();
                }
                else
                {
                    OnBarMovementDecreasingStop?.Invoke();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// On Update we update our bars
        /// </summary>
        protected virtual IEnumerator UpdateBarsCo()
        {
            while (_coroutineShouldRun)
            {
                DetermineDeltaTime();
                DetermineDirection();
                UpdateBars();
                yield return(null);
            }

            CurrentState = MMProgressBarStates.Idle;
            yield break;
        }
Пример #3
0
        /// <summary>
        /// Sets the bar value to the normalized value set in parameter
        /// </summary>
        /// <param name="newPercent"></param>
        public virtual void SetBar01(float newPercent)
        {
            if (!_initialized)
            {
                Initialization();
            }

            newPercent  = MMMaths.Remap(newPercent, 0f, 1f, MinimumBarFillValue, MaximumBarFillValue);
            BarProgress = newPercent;
            DelayedBarDecreasingProgress = newPercent;
            DelayedBarIncreasingProgress = newPercent;
            //_newPercent = newPercent;
            BarTarget = newPercent;
            _percentLastTimeBarWasUpdated = newPercent;
            _delayedBarDecreasingProgress = DelayedBarDecreasingProgress;
            _delayedBarIncreasingProgress = DelayedBarIncreasingProgress;
            SetBarInternal(newPercent, ForegroundBar, _foregroundImage, _initialBarSize);
            SetBarInternal(newPercent, DelayedBarDecreasing, _delayedDecreasingImage, _initialBarSize);
            SetBarInternal(newPercent, DelayedBarIncreasing, _delayedIncreasingImage, _initialBarSize);
            UpdateText();
            _coroutineShouldRun = false;
            CurrentState        = MMProgressBarStates.Idle;
        }