/// <summary> /// Changes the position of a GameObject, relative to it's original position, to the evaluated Vector3 calculated from /// a Vector3AnimationCurve object. /// </summary> /// <param name="gameObject">GameObject to move.</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 PositionRelative(GameObject gameObject, Vector3AnimationCurve animationCurve, float elapsedTime) { var animationData = gameObject.AddOrGetComponent <AnimationData>(); gameObject.transform.localPosition = animationData.TransformData.Position + animationCurve.Evaluate(elapsedTime); }
/// <summary> /// Animates the scale of a GameObject, relative to it's original scale, with a Vector3AnimationCurve. /// </summary> /// <param name="gameObject">GameObject to scale.</param> /// <param name="animationCurve">Vector3AnimationCurve to evaluate.</param> /// <returns>Coroutine</returns> public static Coroutine ScaleRelative(GameObject gameObject, Vector3AnimationCurve animationCurve) { var animationData = gameObject.AddOrGetComponent <AnimationData>(); return(StartCoroutine(gameObject, "ScaleRelative", Loop(gameObject, "ScaleRelative", animationCurve.IsLooping(), animationCurve.MaxTime(), elapsedTime => ScaleRelative(gameObject, animationCurve, elapsedTime, animationData)))); }
/// <summary> /// Animates the scale of a GameObject to the specified Vector3 over time. /// </summary> /// <param name="gameObject">GameObject to scale.</param> /// <param name="newScale">New Vector3 scale.</param> /// <param name="duration">Length of the animation in seconds.</param> /// <returns>Coroutine</returns> public static Coroutine ScaleTo(GameObject gameObject, Vector3 newScale, float duration) { var animationCurve = new Vector3AnimationCurve(); var currentScale = gameObject.transform.localScale; animationCurve.x = AnimationCurve.EaseInOut(0, currentScale.x, duration, newScale.x); animationCurve.y = AnimationCurve.EaseInOut(0, currentScale.y, duration, newScale.y); animationCurve.z = AnimationCurve.EaseInOut(0, currentScale.z, duration, newScale.z); return(Scale(gameObject, animationCurve)); }
public void EditKeyframeValueVector3AnimationCurve() { var animationCurve = new CandyCoded.Vector3AnimationCurve(); animationCurve.x = AnimationCurve.Linear(0, 0, 1, 1); animationCurve.y = AnimationCurve.Linear(0, 0, 1, 1); animationCurve.z = AnimationCurve.Linear(0, 0, 1, 1); animationCurve.EditKeyframeValue(0, new Vector3(10, 15, 20)); Assert.AreEqual(10, animationCurve.x.keys[0].value); Assert.AreEqual(15, animationCurve.y.keys[0].value); Assert.AreEqual(20, animationCurve.z.keys[0].value); Assert.AreEqual(1, animationCurve.x.keys[1].value); Assert.AreEqual(1, animationCurve.y.keys[1].value); Assert.AreEqual(1, animationCurve.z.keys[1].value); }
/// <summary> /// Animates the position of a GameObject to the specified Vector3 over time. /// </summary> /// <param name="gameObject">GameObject to move.</param> /// <param name="newPosition">New Vector3 position.</param> /// <param name="duration">Length of the animation in seconds.</param> /// <param name="relativeTo">Coordinate system used to animate the GameObject.</param> /// <returns>Coroutine</returns> public static Coroutine MoveTo(GameObject gameObject, Vector3 newPosition, float duration, Space relativeTo) { var animationCurve = new Vector3AnimationCurve(); var currentPosition = gameObject.transform.localPosition; if (relativeTo.Equals(Space.World)) { currentPosition = gameObject.transform.position; } animationCurve.x = AnimationCurve.EaseInOut(0, currentPosition.x, duration, newPosition.x); animationCurve.y = AnimationCurve.EaseInOut(0, currentPosition.y, duration, newPosition.y); animationCurve.z = AnimationCurve.EaseInOut(0, currentPosition.z, duration, newPosition.z); return(relativeTo.Equals(Space.World) ? Position(gameObject, animationCurve) : PositionRelative(gameObject, animationCurve)); }
/// <summary> /// Edit the values of the corresponding keyframes in a Vector3AnimationCurve leaving the time and curve of each keyframe untouched. /// </summary> /// <param name="key">Key of each keyframe to modify.</param> /// <param name="vector">Vector3 to update each corresponding keyframe with.</param> /// <returns>void</returns> public static void EditKeyframeValue(this CandyCoded.Vector3AnimationCurve animationCurve, int key, Vector3 vector) { animationCurve.x.EditKeyframeValue(key, vector.x); animationCurve.y.EditKeyframeValue(key, vector.y); animationCurve.z.EditKeyframeValue(key, vector.z); }
/// <summary> /// Changes the scale of a GameObject, relative to it's original scale, to the evaluated Vector3 calculated from a /// Vector3AnimationCurve object. /// </summary> /// <param name="gameObject">GameObject to scale.</param> /// <param name="animationCurve">Vector3AnimationCurve to evaluate.</param> /// <param name="elapsedTime">The time elapsed since the animation started.</param> /// <param name="animationData">AnimationData object containing cached transform data.</param> /// <returns>void</returns> public static void ScaleRelative(GameObject gameObject, Vector3AnimationCurve animationCurve, float elapsedTime, AnimationData animationData) { gameObject.transform.localScale = animationData.TransformData.Scale + animationCurve.Evaluate(elapsedTime); }
/// <summary> /// Changes the scale of a GameObject to the evaluated Vector3 calculated from a Vector3AnimationCurve object. /// </summary> /// <param name="gameObject">GameObject to scale.</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 Scale(GameObject gameObject, Vector3AnimationCurve animationCurve, float elapsedTime) { gameObject.transform.localScale = animationCurve.Evaluate(elapsedTime); }
/// <summary> /// Animates the scale of a GameObject with a Vector3AnimationCurve. /// </summary> /// <param name="gameObject">GameObject to scale.</param> /// <param name="animationCurve">Vector3AnimationCurve to evaluate.</param> /// <returns>Coroutine</returns> public static Coroutine Scale(GameObject gameObject, Vector3AnimationCurve animationCurve) { return(StartCoroutine(gameObject, "Scale", Loop(gameObject, "Scale", animationCurve.IsLooping(), animationCurve.MaxTime(), elapsedTime => Scale(gameObject, animationCurve, elapsedTime)))); }
/// <summary> /// Animates the position of a GameObject with a Vector3AnimationCurve. /// </summary> /// <param name="gameObject">GameObject to move.</param> /// <param name="animationCurve">Vector3AnimationCurve to evaluate.</param> /// <returns>Coroutine</returns> public static Coroutine Position(GameObject gameObject, Vector3AnimationCurve animationCurve) { return(StartCoroutine(gameObject, "Position", Loop(gameObject, "Position", animationCurve.IsLooping(), animationCurve.MaxTime(), (elapsedTime) => Position(gameObject, animationCurve, elapsedTime)))); }