using UnityEngine; using UnityEngine.Events; namespace DuloGames.UI.Tweens { public struct Vector2Tween : ITweenValue { public class Vector2TweenCallback : UnityEvent {} public class Vector2TweenFinishCallback : UnityEvent {} private Vector2 m_StartVector2; private Vector2 m_TargetVector2; private float m_Duration; private bool m_IgnoreTimeScale; private TweenEasing m_Easing; private Vector2TweenCallback m_Target; private Vector2TweenFinishCallback m_Finish; /// /// Gets or sets the starting Vector2. /// /// The start color. public Vector2 startVector2 { get { return m_StartVector2; } set { m_StartVector2 = value; } } /// /// Gets or sets the target Vector2. /// /// The color of the target. public Vector2 targetVector2 { get { return m_TargetVector2; } set { m_TargetVector2 = value; } } /// /// Gets or sets the duration of the tween. /// /// The duration. public float duration { get { return m_Duration; } set { m_Duration = value; } } /// /// Gets or sets a value indicating whether this should ignore time scale. /// /// true if ignore time scale; otherwise, false. public bool ignoreTimeScale { get { return m_IgnoreTimeScale; } set { m_IgnoreTimeScale = value; } } /// /// Gets or sets the tween easing. /// /// The easing. public TweenEasing easing { get { return m_Easing; } set { m_Easing = value; } } /// /// Tweens the color based on percentage. /// /// Float percentage. public void TweenValue(float floatPercentage) { if (!this.ValidTarget()) return; this.m_Target.Invoke( Vector2.Lerp (this.m_StartVector2, this.m_TargetVector2, floatPercentage) ); } /// /// Adds a on changed callback. /// /// Callback. public void AddOnChangedCallback(UnityAction callback) { if (m_Target == null) m_Target = new Vector2TweenCallback(); m_Target.AddListener(callback); } /// /// Adds a on finish callback. /// /// Callback. public void AddOnFinishCallback(UnityAction callback) { if (m_Finish == null) m_Finish = new Vector2TweenFinishCallback(); m_Finish.AddListener(callback); } public bool GetIgnoreTimescale() { return m_IgnoreTimeScale; } public float GetDuration() { return m_Duration; } public bool ValidTarget() { return m_Target != null; } /// /// Invokes the on finish callback. /// public void Finished() { if (m_Finish != null) m_Finish.Invoke(); } } }