예제 #1
0
파일: Tween.cs 프로젝트: slimshader/clingy
        protected override IEnumerator Tween()
        {
            if (tweenOptions.delay > 0)
            {
                yield return(new WaitForSeconds(tweenOptions.delay));
            }

            Transform transform = gameObject.transform;

            rb   = gameObject.GetComponent <Rigidbody>();
            rb2D = gameObject.GetComponent <Rigidbody2D>();

            Vector3 startPosition = transform.position;
            float   timer         = 0;
            float   duration      = Mathf.Max(0, tweenOptions.duration);
            float   speed         = Mathf.Max(0.00001f, tweenOptions.speed);

            Easing.EasingFunction ease = Easing.FromEaseType(tweenOptions.easing);
            firstDestination = GetDestinationPosition();

            bool finished = false;

            while (true)
            {
                Vector3 current      = transform.position;
                Vector3 destination  = tweenOptions.dynamicTarget ? GetDestinationPosition() : firstDestination;
                Vector3 nextPosition = destination;
                if (tweenOptions.tweenMethod == TweenMethod.Speed && timer == 0)
                {
                    duration = (destination - startPosition).magnitude / speed;
                }
                if (tweenOptions.tweenMethod != TweenMethod.None && duration > 0)
                {
                    timer = Mathf.Min(timer + Time.deltaTime, duration);
                    float t = ease(timer, 0, 1, duration);
                    nextPosition = Vector3.LerpUnclamped(startPosition, destination, t);
                    if (timer == duration)
                    {
                        finished = true;
                    }
                }
                else
                {
                    finished = true;
                }

                ClingyUtils.MovePosition(nextPosition, transform, moveMethod, rb, rb2D);

                if (finished)
                {
                    break;
                }
                yield return(null);
            }

            Complete();
        }
예제 #2
0
파일: Tween.cs 프로젝트: slimshader/clingy
        protected override void CompleteTween()
        {
            Vector3 destination = tweenOptions.dynamicTarget ? GetDestinationPosition() : firstDestination;

            ClingyUtils.MovePosition(destination, gameObject.transform, moveMethod, rb, rb2D);
        }