55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.InputSystem.UI;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public class UiNavigationController: MonoBehaviour
|
|
{
|
|
[field: SerializeField]
|
|
public GameObject SelectObject { get; private set; }
|
|
|
|
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)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(SelectObject);
|
|
}
|
|
}
|
|
|
|
public void Enable(GameObject selectObject)
|
|
{
|
|
SelectObject = selectObject;
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
}
|
|
|
|
public void Enable()
|
|
{
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
}
|
|
|
|
public void Disable()
|
|
{
|
|
_inputModule.move.action.performed -= OnNavigate;
|
|
}
|
|
|
|
public void SetSelectObject(GameObject obj)
|
|
{
|
|
SelectObject = obj;
|
|
}
|
|
}
|
|
}
|