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

57 lines
1.4 KiB
C#
Raw Normal View History

2024-11-30 11:53:38 +00:00
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;
}
}
}