Mono ui input manager

This commit is contained in:
Hubert Mattusch 2023-09-14 19:24:38 +02:00
parent b7aa670e70
commit ab5a33742a
3 changed files with 28 additions and 6 deletions

View File

@ -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: "/<Keyboard>/*");
//keyboardAction.performed += (context) => CurrentInputSource = EInputSource.Keyboard;
//keyboardAction.Enable();
var gamepadAction = new InputAction(binding: "/<Gamepad>/*");
gamepadAction.performed += (context) => OnSelectionChangeStarted();
gamepadAction.Enable();
//var gamepadAction = new InputAction(binding: "/<Gamepad>/*");
//gamepadAction.performed += (context) => OnSelectionChangeStarted();
//gamepadAction.Enable();
var mouseAction = new InputAction(binding: "/<Mouse>/*");
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()

View File

@ -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<MonoWindowSlot> windowSlots;

View File

@ -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()
{