diff --git a/Assets/UIComponents.Tests/Editor/Interfaces/UIComponentInterfaceTests.cs b/Assets/UIComponents.Tests/Editor/Interfaces/UIComponentInterfaceTests.cs index 275f87db..7efe5206 100644 --- a/Assets/UIComponents.Tests/Editor/Interfaces/UIComponentInterfaceTests.cs +++ b/Assets/UIComponents.Tests/Editor/Interfaces/UIComponentInterfaceTests.cs @@ -14,14 +14,29 @@ private class BaseTestComponent : UIComponent public bool Fired { get; protected set; } } - private static IEnumerator Assert_Registers_Event_Callback<TComponent, TEvent>() + [SetUp] + public void SetUp() + { + _editorWindow = EditorWindow.GetWindow<InterfacesTestEditorWindow>(); + } + + private InterfacesTestEditorWindow _editorWindow; + + [TearDown] + public void TearDown() + { + if (_editorWindow) + _editorWindow.Close(); + _editorWindow = null; + } + + private IEnumerator Assert_Registers_Event_Callback<TComponent, TEvent>() where TComponent : BaseTestComponent, new() where TEvent : EventBase<TEvent>, new() { - var window = EditorWindow.GetWindow<InterfacesTestEditorWindow>(); var component = new TComponent(); Assert.That(component.Fired, Is.False); - window.AddTestComponent(component); + _editorWindow.AddTestComponent(component); yield return component.WaitForInitializationEnumerator(); @@ -29,7 +44,6 @@ private static IEnumerator Assert_Registers_Event_Callback<TComponent, TEvent>() component.SendEvent(evt); Assert.That(component.Fired, Is.True); - window.Close(); } private class UIComponentWithOnGeometryChanged : BaseTestComponent, IOnGeometryChanged @@ -98,6 +112,18 @@ public IEnumerator IOnClick_Registers_ClickEvent_Callback() { yield return Assert_Registers_Event_Callback<UIComponentWithOnClick, ClickEvent>(); } +#endif +#if UNITY_2021_3_OR_NEWER + private class UIComponentWithOnNavigationMove : BaseTestComponent, IOnNavigationMove + { + public void OnNavigationMove(NavigationMoveEvent evt) => Fired = true; + } + + [UnityTest] + public IEnumerator IOnNavigationMove_Registers_NavigationMoveEvent_Callback() + { + yield return Assert_Registers_Event_Callback<UIComponentWithOnNavigationMove, NavigationMoveEvent>(); + } #endif } } diff --git a/Assets/UIComponents/Core/EventInterfaces/IOnClick.cs b/Assets/UIComponents/Core/EventInterfaces/IOnClick.cs index f95bd83c..f560fc77 100644 --- a/Assets/UIComponents/Core/EventInterfaces/IOnClick.cs +++ b/Assets/UIComponents/Core/EventInterfaces/IOnClick.cs @@ -13,4 +13,4 @@ public interface IOnClick void OnClick(ClickEvent evt); } } -#endif \ No newline at end of file +#endif diff --git a/Assets/UIComponents/Core/EventInterfaces/IOnNavigationMove.cs b/Assets/UIComponents/Core/EventInterfaces/IOnNavigationMove.cs new file mode 100644 index 00000000..499543b4 --- /dev/null +++ b/Assets/UIComponents/Core/EventInterfaces/IOnNavigationMove.cs @@ -0,0 +1,16 @@ +#if UNITY_2021_3_OR_NEWER +using UnityEngine.UIElements; + +namespace UIComponents +{ + /// <summary> + /// When implemented by a <see cref="UIComponent"/>, + /// a callback for <see cref="NavigationMoveEvent"/> is + /// automatically registered in the UIComponent constructor. + /// </summary> + public interface IOnNavigationMove + { + void OnNavigationMove(NavigationMoveEvent evt); + } +} +#endif diff --git a/Assets/UIComponents/Core/EventInterfaces/IOnNavigationMove.cs.meta b/Assets/UIComponents/Core/EventInterfaces/IOnNavigationMove.cs.meta new file mode 100644 index 00000000..f8620656 --- /dev/null +++ b/Assets/UIComponents/Core/EventInterfaces/IOnNavigationMove.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e04f403918934a448a9afc3a71c9b898 +timeCreated: 1663609181 \ No newline at end of file diff --git a/Assets/UIComponents/Core/UIComponent.cs b/Assets/UIComponents/Core/UIComponent.cs index 16b114a4..788f04e9 100644 --- a/Assets/UIComponents/Core/UIComponent.cs +++ b/Assets/UIComponents/Core/UIComponent.cs @@ -151,6 +151,10 @@ private void RegisterEventInterfaceCallbacks() #if UNITY_2020_3_OR_NEWER if (this is IOnClick onClick) RegisterCallback<ClickEvent>(onClick.OnClick); +#endif +#if UNITY_2021_3_OR_NEWER + if (this is IOnNavigationMove onNavigationMove) + RegisterCallback<NavigationMoveEvent>(onNavigationMove.OnNavigationMove); #endif }