2024-11-30 11:53:38 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using UnityEngine.InputSystem.UI;
|
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
2024-12-03 12:30:09 +00:00
|
|
|
public class UiEventsController: MonoBehaviour
|
2024-11-30 11:53:38 +00:00
|
|
|
{
|
2024-12-02 01:48:44 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public GameObject SelectObject { get; private set; }
|
2024-11-30 11:53:38 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2024-12-02 01:48:44 +00:00
|
|
|
EventSystem.current.SetSelectedGameObject(SelectObject);
|
2024-11-30 11:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:30:09 +00:00
|
|
|
public void SetSelectObject(GameObject obj)
|
|
|
|
{
|
|
|
|
SelectObject = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EnableAutoNavigate(GameObject selectObject)
|
2024-11-30 11:53:38 +00:00
|
|
|
{
|
2024-12-02 01:48:44 +00:00
|
|
|
SelectObject = selectObject;
|
2024-11-30 11:53:38 +00:00
|
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:30:09 +00:00
|
|
|
public void EnableAutoNavigate()
|
2024-11-30 11:53:38 +00:00
|
|
|
{
|
|
|
|
_inputModule.move.action.performed += OnNavigate;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:30:09 +00:00
|
|
|
public void DisableAutoNavigate()
|
2024-11-30 11:53:38 +00:00
|
|
|
{
|
|
|
|
_inputModule.move.action.performed -= OnNavigate;
|
2024-12-02 01:48:44 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:30:09 +00:00
|
|
|
public void EnableUiActions()
|
2024-12-02 01:48:44 +00:00
|
|
|
{
|
2024-12-03 12:30:09 +00:00
|
|
|
_inputModule.actionsAsset.Enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisableUiActions()
|
|
|
|
{
|
|
|
|
_inputModule.actionsAsset.Disable();
|
2024-11-30 11:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|