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>(); Quaternion startRotation = transform.rotation; 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 = GetDestinationRotation(); bool finished = false; while (true) { Quaternion current = transform.rotation; Quaternion destination = tweenOptions.dynamicTarget ? GetDestinationRotation() : firstDestination; Quaternion nextRotation = destination; if (tweenOptions.tweenMethod == TweenMethod.Speed && timer == 0) { duration = Quaternion.Angle(startRotation, destination) / speed; } if (tweenOptions.tweenMethod != TweenMethod.None && duration > 0) { timer = Mathf.Min(timer + Time.deltaTime, duration); float t = ease(timer, 0, 1, duration); nextRotation = Quaternion.LerpUnclamped(startRotation, destination, t); if (timer == duration) { finished = true; } } else { finished = true; } ClingyUtils.MoveRotation(nextRotation, transform, rotateMethod, rb, rb2D); if (finished) { break; } yield return(null); } Complete(); }
protected override void CompleteTween() { Quaternion destination = tweenOptions.dynamicTarget ? GetDestinationRotation() : firstDestination; ClingyUtils.MoveRotation(destination, gameObject.transform, rotateMethod, rb, rb2D); }