Esempio n. 1
0
        private IEnumerator TweenCoro(Action <float> onTween = null)
        {
            var   startTime   = Time.time;
            float elapsedTime = 0;

            _isPlaying = true;
            float realT;
            bool  keepPlaying = true;

            do
            {
                if (!_isPlaying)
                {
                    yield break;
                }
                if (Loop == LoopType.Loop || Loop == LoopType.ReturnAndLoop)
                {
                    elapsedTime = (Time.time - startTime) % Duration;
                }
                else
                {
                    elapsedTime = Mathf.Min(Time.time - startTime, Duration);
                }
                if (Loop == LoopType.ReturnAndLoop || Loop == LoopType.ReturnOnce)
                {
                    realT        = Mathf.Min(elapsedTime, Duration) / Duration;
                    CurrentValue = 1 - Mathf.Abs((realT * 2) - 1);
                }
                else
                {
                    CurrentValue = elapsedTime / Duration;
                    realT        = CurrentValue;
                }
                Tween(GetDelta(CurrentValue));
                OnTween?.Invoke(this, CurrentValue);
                onTween?.Invoke(CurrentValue);

                yield return(new WaitForEndOfFrame());

                bool timeOver = realT >= 1;
                if (Loop == LoopType.Loop || Loop == LoopType.ReturnAndLoop)
                {
                    keepPlaying = _isPlaying;
                }
                else
                {
                    keepPlaying = !timeOver && _isPlaying;
                }
            }while (keepPlaying);

            var promise = _lastPromise;

            _isPlaying     = false;
            _lastPromise   = null;
            _lastCoroutine = null;
            promise.Resolve();
        }
Esempio n. 2
0
        public void TweenValue(float tweenPercent)
        {
            if (!IsTargetValid)
            {
                return;
            }

            var newValue = new Vector3(
                TweenFloat(StartValue.x, TargetValue.x, tweenPercent),
                TweenFloat(StartValue.y, TargetValue.y, tweenPercent),
                TweenFloat(StartValue.z, TargetValue.z, tweenPercent)
                );

            OnTween.Invoke(newValue);
        }