Esempio n. 1
0
        /// <summary>
        ///     Animates the rotation of a GameObject to the specified Quaternion over time.
        /// </summary>
        /// <param name="gameObject">GameObject to rotate.</param>
        /// <param name="newRotation">New Quaternion rotation.</param>
        /// <param name="duration">Length of the animation in seconds.</param>
        /// <returns>Coroutine</returns>
        public static Coroutine RotateTo(GameObject gameObject, Quaternion newRotation, float duration)
        {
            var animationCurve = new Vector4AnimationCurve();

            var currentRotation = gameObject.transform.localRotation;

            var newRotationCopy = Quaternion.SlerpUnclamped(currentRotation, newRotation, 1);

            animationCurve.x = AnimationCurve.EaseInOut(0, currentRotation.x, duration, newRotationCopy.x);
            animationCurve.y = AnimationCurve.EaseInOut(0, currentRotation.y, duration, newRotationCopy.y);
            animationCurve.z = AnimationCurve.EaseInOut(0, currentRotation.z, duration, newRotationCopy.z);
            animationCurve.w = AnimationCurve.EaseInOut(0, currentRotation.w, duration, newRotationCopy.w);

            return(Rotation(gameObject, animationCurve));
        }
Esempio n. 2
0
        /// <summary>
        ///     Changes the rotation of a GameObject to the evaluated Vector3 calculated from a Vector3AnimationCurve object.
        /// </summary>
        /// <param name="gameObject">GameObject to rotate.</param>
        /// <param name="animationCurve">Vector3AnimationCurve to evaluate.</param>
        /// <param name="elapsedTime">The time elapsed since the animation started.</param>
        /// <returns>void</returns>
        public static void Rotation(GameObject gameObject, Vector4AnimationCurve animationCurve, float elapsedTime)
        {
            var rotation = animationCurve.Evaluate(elapsedTime);

            gameObject.transform.localRotation = new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w);
        }
Esempio n. 3
0
 /// <summary>
 ///     Animates the rotation of a GameObject with a Vector3AnimationCurve.
 /// </summary>
 /// <param name="gameObject">GameObject to rotate.</param>
 /// <param name="animationCurve">Vector3AnimationCurve to evaluate.</param>
 /// <returns>Coroutine</returns>
 public static Coroutine Rotation(GameObject gameObject, Vector4AnimationCurve animationCurve)
 {
     return(StartCoroutine(gameObject, "Rotation",
                           Loop(gameObject, "Rotation", animationCurve.IsLooping(), animationCurve.MaxTime(),
                                elapsedTime => Rotation(gameObject, animationCurve, elapsedTime))));
 }