65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.InputSystem.UI;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public class UiEventsController : 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 SetSelectObject(GameObject obj)
|
|
{
|
|
SelectObject = obj;
|
|
}
|
|
|
|
public void EnableAutoNavigate(GameObject selectObject)
|
|
{
|
|
SelectObject = selectObject;
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
}
|
|
|
|
public void EnableAutoNavigate()
|
|
{
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
}
|
|
|
|
public void DisableAutoNavigate()
|
|
{
|
|
_inputModule.move.action.performed -= OnNavigate;
|
|
}
|
|
|
|
public void EnableUiActions()
|
|
{
|
|
_inputModule.actionsAsset.Enable();
|
|
}
|
|
|
|
public void DisableUiActions()
|
|
{
|
|
_inputModule.actionsAsset.Disable();
|
|
}
|
|
}
|
|
}
|