public UIAnimation( UIObject sprite, float duration, UIAnimationProperty aniProperty, Vector3 start, Vector3 target, System.Func<float, float> ease ) { this.sprite = sprite; this.duration = duration; _aniProperty = aniProperty; this.ease = ease; this.target = target; this.start = start; _running = true; startTime = Time.realtimeSinceStartup; }
public UIAnimation( UIObject sprite, float duration, UIAnimationProperty aniProperty, Color startColor, Color targetColor, System.Func<float, float> ease ) { this.sprite = sprite; this.duration = duration; _aniProperty = aniProperty; this.ease = ease; this.startColor = startColor; this.targetColor = targetColor; _running = true; startTime = Time.realtimeSinceStartup; }
public UIAnimation( UIObject sprite, float duration, UIAnimationProperty aniProperty, float startFloat, float targetFloat, System.Func<float, float> ease ) { this.sprite = sprite; this.duration = duration; _aniProperty = aniProperty; this.ease = ease; this.targetFloat = targetFloat; this.startFloat = startFloat; _running = true; startTime = Time.time; }
public UIAnimation(UIObject sprite, float duration, UIAnimationProperty aniProperty, float startFloat, float targetFloat, System.Func<float, float> ease, bool affectedByTimeScale = true) { this.sprite = sprite; this.duration = duration; _aniProperty = aniProperty; this.ease = ease; this.affectedByTimeScale = affectedByTimeScale; this.targetFloat = targetFloat; this.startFloat = startFloat; _running = true; startTime = affectedByTimeScale ? Time.time : Time.realtimeSinceStartup; }
// Figures out the start value and kicks off the animation - Vector3 version private static UIAnimation animate( UIObject sprite, bool animateTo, float duration, UIAnimationProperty aniProperty, Vector3 target, UIEaseType ease ) { Vector3 current = Vector3.zero; // Grab the current value switch( aniProperty ) { case UIAnimationProperty.Position: current = sprite.localPosition; break; case UIAnimationProperty.Scale: current = sprite.scale; break; case UIAnimationProperty.EulerAngles: current = sprite.eulerAngles; break; } Vector3 start = ( animateTo ) ? current : target; // If we are doing a 'from', the target is our current position if( !animateTo ) target = current; return animate( sprite, duration, aniProperty, start, target, ease ); }
// Sets up and starts a new animation in a Coroutine - Vector3 version private static UIAnimation animate( UIObject sprite, float duration, UIAnimationProperty aniProperty, Vector3 start, Vector3 target, UIEaseType ease ) { var ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease ); UI.Instance.StartCoroutine( ani.animate() ); return ani; }
// Figures out the start value and kicks off the animation - float version private static UIAnimation animate( UIObject sprite, bool animateTo, float duration, UIAnimationProperty aniProperty, float target, UIEaseType ease ) { float current = 0.0f; // Grab the current value switch( aniProperty ) { case UIAnimationProperty.Alpha: current = sprite.color.a; break; } float start = ( animateTo ) ? current : target; // If we are doing a 'from', the target is our current position if( !animateTo ) target = current; return animate( sprite, duration, aniProperty, start, target, ease ); }
// Figures out the start value and kicks off the animation - Color version private static UIAnimation animate( UIObject sprite, bool animateTo, float duration, UIAnimationProperty aniProperty, Color target, UIEaseType ease ) { // Grab the current value Color current = sprite.color; Color start = ( animateTo ) ? current : target; // If we are doing a 'from', the target is our current position if( !animateTo ) target = current; return animate( sprite, duration, aniProperty, start, target, ease ); }
// Vector3 version public static UIAnimation fromTo( this UIObject sprite, float duration, UIAnimationProperty aniProperty, Vector3 start, Vector3 target, UIEaseType ease ) { return animate( sprite, duration, aniProperty, start, target, ease ); }
// Color version public static UIAnimation from( this UIObject sprite, float duration, UIAnimationProperty aniProperty, Color target, UIEaseType ease ) { return animate( sprite, false, duration, aniProperty, target, ease ); }
// float version (for alpha) public static UIAnimation to( this UIObject sprite, float duration, UIAnimationProperty aniProperty, float target, UIEaseType ease ) { return animate( sprite, true, duration, aniProperty, target, ease ); }
public UIAnimation(UIObject sprite, float duration, UIAnimationProperty aniProperty, Color startColor, Color targetColor, System.Func <float, float> ease) : this(sprite, duration, aniProperty, startColor, targetColor, ease, true) { }
public UIAnimation(UIObject sprite, float duration, UIAnimationProperty aniProperty, float startFloat, float targetFloat, System.Func <float, float> ease) : this(sprite, duration, aniProperty, startFloat, targetFloat, ease, true) { }