CapersProject/Assets/02.Scripts/Ui/UiNavigationController.cs

55 lines
1.4 KiB
C#
Raw Normal View History

2024-11-30 11:53:38 +00:00
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.UI;
namespace BlueWater
{
public class UiNavigationController: MonoBehaviour
{
2024-12-02 01:48:44 +00:00
[field: SerializeField]
public GameObject SelectObject { get; private set; }
2024-11-30 11:53:38 +00:00
private InputSystemUIInputModule _inputModule;
private void Awake()
{
_inputModule = EventSystem.current.GetComponent<InputSystemUIInputModule>();
}
private void OnDestroy()
{
_inputModule.move.action.performed -= OnNavigate;
}
private void OnNavigate(InputAction.CallbackContext context)
{
if (EventSystem.current.currentSelectedGameObject == null)
{
2024-12-02 01:48:44 +00:00
EventSystem.current.SetSelectedGameObject(SelectObject);
2024-11-30 11:53:38 +00:00
}
}
public void Enable(GameObject selectObject)
{
2024-12-02 01:48:44 +00:00
SelectObject = selectObject;
2024-11-30 11:53:38 +00:00
_inputModule.move.action.performed += OnNavigate;
}
public void Enable()
{
_inputModule.move.action.performed += OnNavigate;
}
public void Disable()
{
_inputModule.move.action.performed -= OnNavigate;
2024-12-02 01:48:44 +00:00
}
public void SetSelectObject(GameObject obj)
{
SelectObject = obj;
2024-11-30 11:53:38 +00:00
}
}
}