///Credit ChoMPHi ///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/ using UnityEngine.Events; namespace UnityEngine.UI.Extensions.Tweens { public struct FloatTween : ITweenValue { public class FloatTweenCallback : UnityEvent {} public class FloatFinishCallback : UnityEvent {} private float m_StartFloat; private float m_TargetFloat; private float m_Duration; private bool m_IgnoreTimeScale; private FloatTweenCallback m_Target; private FloatFinishCallback m_Finish; /// /// Gets or sets the starting float. /// /// The start float. public float startFloat { get { return m_StartFloat; } set { m_StartFloat = value; } } /// /// Gets or sets the target float. /// /// The target float. public float targetFloat { get { return m_TargetFloat; } set { m_TargetFloat = 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; } } /// /// Tweens the float based on percentage. /// /// Float percentage. public void TweenValue(float floatPercentage) { if (!ValidTarget()) return; m_Target.Invoke( Mathf.Lerp (m_StartFloat, m_TargetFloat, floatPercentage) ); } /// /// Adds a on changed callback. /// /// Callback. public void AddOnChangedCallback(UnityAction callback) { if (m_Target == null) m_Target = new FloatTweenCallback(); m_Target.AddListener(callback); } /// /// Adds a on finish callback. /// /// Callback. public void AddOnFinishCallback(UnityAction callback) { if (m_Finish == null) m_Finish = new FloatFinishCallback(); 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(); } } }