57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.InputSystem.UI;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public class UiNavigationController: MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject _selectObject;
|
|
|
|
[SerializeField]
|
|
private bool _isEnable;
|
|
|
|
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;
|
|
_isEnable = true;
|
|
}
|
|
|
|
public void Enable()
|
|
{
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
_isEnable = true;
|
|
}
|
|
|
|
public void Disable()
|
|
{
|
|
_inputModule.move.action.performed -= OnNavigate;
|
|
_isEnable = false;
|
|
}
|
|
}
|
|
}
|