using TowerDefense.Towers; using UnityEngine; namespace TowerDefense.UI.HUD { /// /// A class that controls the information display /// whilst dragging the ghost tower /// [RequireComponent(typeof(TowerUI))] public class BuildInfoUI : MonoBehaviour { /// /// an enum for easily keeping track of UI animation /// public enum AnimationState { /// /// The UI is completely hidden /// Hidden, /// /// The UI is animation to be shown /// Showing, /// /// the UI is completely shown /// Shown, /// /// The UI is animating /// Hiding } /// /// The attached animator /// public Animation anim; /// /// The name of the clip that shows the UI /// public string showClipName = "Show"; /// /// The name of the clip that hides the UI /// public string hideClipName = "Hide"; /// /// The attached /// protected TowerUI m_TowerUI; /// /// The attached canvas /// protected Canvas m_Canvas; /// /// Tracks the animation of the UI /// AnimationState m_State; /// /// NOTE: Plays from Show animation clip event /// Fires at the end of the show animation /// Sets to Show /// public void ShowEnd() { m_State = AnimationState.Shown; } /// /// NOTE: Plays from Hide animation clip event /// Fires at the end of the hide animation /// Sets to Hidden /// public void HideEnd() { m_State = AnimationState.Hidden; } /// /// Shows the information /// /// /// The tower information to display /// public virtual void Show(Tower controller) { m_TowerUI.Show(controller); if (m_State == AnimationState.Shown) { return; } anim.Play(showClipName); if (m_State == AnimationState.Hiding) { anim[showClipName].normalizedTime = 1; m_State = AnimationState.Shown; return; } m_State = anim[showClipName].normalizedTime < 1 ? AnimationState.Showing : AnimationState.Shown; } /// /// Hides the information /// public virtual void Hide() { if (m_State == AnimationState.Hidden) { return; } m_TowerUI.Hide(); anim.Play(hideClipName); m_State = anim[hideClipName].normalizedTime < 1 ? AnimationState.Hiding : AnimationState.Hidden; } /// /// Cache the attached Canvas and the attached TowerControllerUI /// protected virtual void Awake() { m_Canvas = GetComponent(); m_TowerUI = GetComponent(); } } }