Esempio n. 1
0
        protected override void Operation(float percentage)
        {
            Rect calculatedValue = TweenUtilities.LinearInterpolate(_start, EndValue, percentage);

            _valueUpdatedCallback(calculatedValue);
        }
Esempio n. 2
0
        protected override void Operation(float percentage)
        {
            Color calculatedValue = TweenUtilities.LinearInterpolate(_start, EndValue, percentage);

            _target.SetColor(_propertyName, calculatedValue);
        }
Esempio n. 3
0
        /// <summary>
        /// Used internally to update the tween and report status to the main system.
        /// </summary>
        public bool Tick()
        {
            //stop where we are:
            if (Status == Tween.TweenStatus.Stopped)
            {
                return(false);
            }

            //rewind operation and stop:
            if (Status == Tween.TweenStatus.Canceled)
            {
                Operation(0);
                Percentage = 0;
                return(false);
            }

            //fast forward operation and stop:
            if (Status == Tween.TweenStatus.Finished)
            {
                Operation(1);
                Percentage = 1;
                if (CompleteCallback != null)
                {
                    CompleteCallback();
                }
                return(false);
            }

            //calculate:
            float progress = 0;

            if (ObeyTimescale)
            {
                progress = Mathf.Max((Time.time - _startTime), 0);
            }
            else
            {
                progress = Mathf.Max((Time.realtimeSinceStartup - _startTime), 0);
            }

            //percentage:
            float percentage = Mathf.Min(progress / Duration, 1);

            //delayed?
            if (percentage == 0 && Status != Tween.TweenStatus.Delayed)
            {
                Status = Tween.TweenStatus.Delayed;
            }

            //running?
            if (percentage > 0 && Status == Tween.TweenStatus.Delayed)
            {
                Tween.Stop(targetInstanceID, tweenType);
                if (SetStartValue())
                {
                    if (StartCallback != null)
                    {
                        StartCallback();
                    }
                    Status = Tween.TweenStatus.Running;
                }
                else
                {
                    return(false);
                }
            }

            //evaluate:
            float curveValue = percentage;

            //using a curve?
            if (Curve != null && CurveKeys.Length > 0)
            {
                curveValue = TweenUtilities.EvaluateCurve(Curve, percentage);
            }

            //perform operation with minimal overhead of a try/catch to account for anything that has been destroyed while tweening:
            if (Status == Tween.TweenStatus.Running)
            {
                try
                {
                    Operation(curveValue);
                    Percentage = curveValue;
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }

            //tween complete:
            if (percentage == 1)
            {
                if (CompleteCallback != null)
                {
                    CompleteCallback();
                }
                switch (LoopType)
                {
                case Tween.LoopType.Loop:
                    Loop();
                    break;

                case Tween.LoopType.PingPong:
                    PingPong();
                    break;

                default:
                    Status = Tween.TweenStatus.Finished;
                    return(false);
                }
            }

            //tell system we are still have work to do:
            return(true);
        }
Esempio n. 4
0
        protected override void Operation(float percentage)
        {
            Vector3 calculatedValue = TweenUtilities.LinearInterpolate(_start, EndValue, percentage);

            _target.localScale = calculatedValue;
        }
        protected override void Operation(float percentage)
        {
            Color calculatedValue = TweenUtilities.LinearInterpolate(_start, EndValue, percentage);

            _target.color = calculatedValue;
        }
        protected override void Operation(float percentage)
        {
            Quaternion calculatedValue = Quaternion.Euler(TweenUtilities.LinearInterpolateRotational(_start, EndValue, percentage));

            _target.localRotation = calculatedValue;
        }
        protected override void Operation(float percentage)
        {
            float calculatedValue = TweenUtilities.LinearInterpolate(_start, EndValue, percentage);

            _target.fieldOfView = calculatedValue;
        }