diff --git a/Editor/VioletButtonEditor.cs b/Editor/VioletButtonEditor.cs index 910e1c4..8984831 100644 --- a/Editor/VioletButtonEditor.cs +++ b/Editor/VioletButtonEditor.cs @@ -7,10 +7,9 @@ namespace VioletUI { [CustomEditor(typeof(VioletButton))] public class VioletButtonEditor : ButtonEditor { public override void OnInspectorGUI() { + base.OnInspectorGUI(); VioletButton button = (VioletButton)target; - button.visitScreen = (ScreenId)EditorGUILayout.EnumPopup("Visit Screen", button.visitScreen); - base.OnInspectorGUI(); } } } diff --git a/Runtime/Navigation/VioletButton.cs b/Runtime/Navigation/VioletButton.cs index aa72e25..dce1160 100644 --- a/Runtime/Navigation/VioletButton.cs +++ b/Runtime/Navigation/VioletButton.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.EventSystems; +using System; #if UNITY_EDITOR using UnityEditor; #endif @@ -8,6 +9,8 @@ namespace VioletUI { [ExecuteAlways] public class VioletButton : UnityEngine.UI.Button { public ScreenId visitScreen; + [NonSerialized] + public bool isSelected; protected Navigator navigator; protected override void Awake() { @@ -16,6 +19,14 @@ protected override void Awake() { Violet.LogVerbose($"Button awoken. navigator={navigator}"); } + protected virtual void Submit() { + Violet.LogVerbose($"Button {name} clicked"); + if (visitScreen != ScreenId.None) { + Violet.LogVerbose($"Visiting {visitScreen} navigator={navigator}"); + _ = navigator.Visit(visitScreen); + } + } + protected override void OnEnable() { base.OnEnable(); this.onClick.AddListener(Submit); @@ -24,6 +35,7 @@ protected override void OnEnable() { protected override void OnDisable() { base.OnDisable(); this.onClick.RemoveListener(Submit); + isSelected = false; } protected override void OnDestroy() { @@ -31,12 +43,14 @@ protected override void OnDestroy() { this.onClick.RemoveListener(Submit); } - protected virtual void Submit() { - Violet.LogVerbose($"Button {name} clicked"); - if (visitScreen != ScreenId.None) { - Violet.LogVerbose($"Visiting {visitScreen} navigator={navigator}"); - navigator.Visit(visitScreen); - } + public override void OnSelect(BaseEventData eventData) { + base.OnSelect(eventData); + isSelected = true; + } + + public override void OnDeselect(BaseEventData eventData) { + base.OnDeselect(eventData); + isSelected = false; } #if UNITY_EDITOR @@ -65,6 +79,8 @@ void OnGUI() { Violet.LogVerbose($"transform.position={transform.position} topLeft={topLeft} bottomRight={bottomRight} mousePosition={mousePosition}"); } } + #endif } + } \ No newline at end of file