From ab5a33742a1ca37a4d71e38de06cc84092101d5c Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Thu, 14 Sep 2023 19:24:38 +0200 Subject: [PATCH] Mono ui input manager --- NEG/UI/UnityUi/MonoUiInputManger.cs | 23 +++++++++++++++---- NEG/UI/UnityUi/Window/MonoWindow.cs | 1 + .../WindowSlot/SingleWindowSlotWithHistory.cs | 10 ++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index 22cd060..4f87f94 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using NEG.UI.UnityUi.Window; +using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.InputSystem; using UnityEngine.InputSystem.UI; @@ -31,9 +32,9 @@ namespace NEG.UI.UnityUi //var keyboardAction = new InputAction(binding: "//*"); //keyboardAction.performed += (context) => CurrentInputSource = EInputSource.Keyboard; //keyboardAction.Enable(); - var gamepadAction = new InputAction(binding: "//*"); - gamepadAction.performed += (context) => OnSelectionChangeStarted(); - gamepadAction.Enable(); + //var gamepadAction = new InputAction(binding: "//*"); + //gamepadAction.performed += (context) => OnSelectionChangeStarted(); + //gamepadAction.Enable(); var mouseAction = new InputAction(binding: "//*"); mouseAction.performed += (context) => @@ -56,6 +57,20 @@ namespace NEG.UI.UnityUi { CurrentSelectionSource = SelectionSource.Direction; Cursor.visible = false; + if (EventSystem.current.currentSelectedGameObject == null) + { + EventSystem.current.SetSelectedGameObject(((MonoWindow)MonoUiManager.Instance.CurrentMainWindow).DefaultSelectedItem); + return; + } + var data = new PointerEventData(EventSystem.current); + var currentSelected = EventSystem.current.currentSelectedGameObject; + for (var current = EventSystem.current.currentSelectedGameObject.transform; + current != null; + current = current.parent) + { + ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); + } + EventSystem.current.SetSelectedGameObject(currentSelected); } private void SetPointerInput() diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index ddbc35a..db8b882 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -24,6 +24,7 @@ namespace NEG.UI.UnityUi.Window public bool IsMainWindow { get; private set; } private IWindowSlot DefaultWindowSlot => windowSlots[0]; + public GameObject DefaultSelectedItem => defaultSelectedItem; [SerializeField] private List windowSlots; diff --git a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs index a718257..10d010e 100644 --- a/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs +++ b/NEG/UI/UnityUi/WindowSlot/SingleWindowSlotWithHistory.cs @@ -1,7 +1,10 @@ -using NEG.UI.UnityUi.WindowSlot; +using NEG.UI; +using NEG.UI.UnityUi.Window; +using NEG.UI.UnityUi.WindowSlot; using NEG.UI.Window; using System.Collections.Generic; using System.Linq; +using UnityEngine.EventSystems; namespace NegUtils.NEG.UI.UnityUi.WindowSlot { @@ -41,8 +44,11 @@ namespace NegUtils.NEG.UI.UnityUi.WindowSlot window.SetClosedState(); windowsHistory.Remove(window); if (window != currentWindow || windowsHistory.Count == 0) return; - windowsHistory[^1].SeVisibleState(); currentWindow = windowsHistory[^1]; + currentWindow.SeVisibleState(); + if(UiManager.Instance.CurrentMainWindow == window) + UiManager.Instance.SetMainWindow(currentWindow); + EventSystem.current.SetSelectedGameObject(((MonoWindow)currentWindow).DefaultSelectedItem); } public override void CloseAllWindows() {