ObjectAnimations

ObjectAnimations#

NAMESPACE:

UnityUtils.ScriptUtils.Objects

The ObjectAnimations script is used to help with animating object values, things like position, script values, etc. Be careful when using this because overlapping animations going on of the same value can be an issue

Example Usage#

 using UnityEngine;
 using UnityUtils.ScriptUtils.Objects;

 public class ExampleScript : MonoBehaviour
 {
      public AnimationCurve animationCurve;
      public bool useRealtime;

      public float testingValue;
      public Vector3 testingVector3;

      void Start()
      {
      // Animates an objects rotation value from its current rotation to (4, 50, 90) in 2 seconds.
      ObjectAnimations.AnimateTransformRotation(transform, new Vector3(transform.localRotation.x, transform.localRotation.y, transform.localRotation.z), new Vector3(4, 50, 90), 2, useRealtime, animationCurve);

      // Animates an objects scale  value from its current rotation to (3, 4, 5) in 2 seconds.
      ObjectAnimations.AnimateTransformScale(transform, transform.localScale, new Vector3(3, 4, 5), 2, useRealtime, animationCurve);

      // Animates an objects position value from its current rotation to (0, 5, 0) in 2 seconds.
      ObjectAnimations.AnimateTransformPosition(transform, transform.position, new Vector3(0, 5, 0), 2, useRealtime, animationCurve);

      // Animates the testingVector3 variable's value from (0, 0, 0) to (0, 1, 4) in 2 seconds.
      ObjectAnimations.AnimateValue<Vector3>(new Vector3(0, 0, 0), new Vector3(2, 2, 2), 2, (a, b, t) => Vector3.Lerp(a, b, t), value => testingVector3 = value);

      // Animates the testingValue variable's value from 1 to 3 in 2 seconds.
      ObjectAnimations.AnimateValue<float>(1, 3, 2, (a, b, t) => Mathf.Lerp(a, b, t), value => testingValue = value);
   }
}

Functions#

UnityUtils.ScriptUtils.Objects.ObjectAnimations

Public Static Functions

void AnimateTransformScale(Transform transform, Vector3 startScale, Vector3 endScale, float duration, bool useRealtime = false, AnimationCurve animationCurve = default)#

Animates an objects Transform components scale from a starting value to an ending value over a specified duration.

void AnimateTransformPosition(Transform transform, Vector3 startPos, Vector3 endPos, float duration, bool useRealtime = false, AnimationCurve animationCurve = default)#

Animates an objects Transform components position from a starting value to an ending value over a specified duration.

void AnimateTransformRotation(Transform transform, Vector3 startRotation, Vector3 endRotation, float duration, bool useRealtime = false, AnimationCurve animationCurve = default)#

Animates an objects Transform components rotation from a starting value to an ending value over a specified duration.

void AnimateSpriteRendererOpacity(SpriteRenderer spriteRenderer, float startOpacity, float endOpacity, float duration, bool useRealtime = false, AnimationCurve animationCurve = default)#

Animates an objects SpriteRenderer component alpha from a starting value to an ending value over a specified duration.

void AnimateImageOpacity(Image image, float startOpacity, float endOpacity, float duration, bool useRealtime = false, AnimationCurve animationCurve = default)#

Animates an objects Image component alpha from a starting value to an ending value over a specified duration.

void AnimateCanvasGroupOpacity(CanvasGroup group, float startOpacity, float endOpacity, float duration, bool useRealtime = false, AnimationCurve animationCurve = default)#

Animates an objects CanvasGroup component alpha from a starting value to an ending value over a specified duration.

void AnimateAudioVolume(AudioSource audioSource, float startVolume, float endVolume, float duration, bool useRealtime = true)#

Animates an objects AudioSource component volume from a starting value to an ending value over a specified duration.

void FadeOutAudio(AudioSource audioSource, float duration, bool useRealtime = true)#

Animates an objects AudioSource component volume from its current volume to 0.

void FadeInAudio(AudioSource audioSource, float duration, float endVolume = 1, bool useRealtime = true)#

Animates an objects AudioSource component volume from 0 to a specified volume.

template<>
void AnimateValue<T>(T start, T end, float duration, Func<T, T, float, T> lerpFunction, Action<T> onValueChanged, bool useRealtime = false, AnimationCurve curve = default)#

Animates a value from a starting value to an ending value over a specified duration.

Parameters:
  • lerpFunction – Decides how the start and end are lerped. Use things like Mathf.Lerp() or Vector3.Lerp() for different types of values

  • onValueChanged – A callback that is invoked with the current interpolated Vector3 value as the animation progresses

  • useRealtime – true to use unscaled real time for the animation (ignoring time scale)

  • animationCurve – Default is a linear curve