CapersProject/Assets/02.Scripts/Ui/UiNavigationController.cs
Nam Tae Gun 7848033d4e 0.3.5.3
2024-12-02 10:48:44 +09:00

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;
}
}
}