Пример #1
0
        public override Tweener MoveTo(float tweenPos)
        {
            if (Duration <= 0)
            {
                throw new Exception("Tweener.MoveTo failed: duration error");
            }

            if (Status != State.Active)
            {
                return(this);
            }

            if ((null != Validator) && !Validator())
            {
                StateTransition(State.Terminated);
                return(this);
            }

            TweenPos      = tweenPos;
            FinishedLoops = Mathf.FloorToInt(TweenPos / Duration);
            if (Loop > 0 && FinishedLoops >= Loop)   // todo: consider about this
            {
                StateTransition(State.Complete);
            }

            var inLoopPos = TweenPos % Duration;

            if (Status == State.Complete) // edge condition: 0 or Duration(max) ?
            {
                inLoopPos = Duration;     // if the tween is completed, the tween pos should be the duration * loops
            }

            var posScale = inLoopPos / Duration;

            if (
                Direction == Directions.Backward ||
                (Direction == Directions.PingPong && (FinishedLoops & 1) == 1)
                )
            {
                posScale = 1 - posScale;
            }

            Setter(Evaluator.Evaluate(ValFrom, ValTo, Ease.Convert(posScale)));

            return(this);
        }