- Added multiple input modes: - Point and click (as before) - WASD + mouse aiming (fully supported) (need QoL for interactables) - Gamepad controls (partial support) - Sprite indexer to avoid gamebreaking issues when serializing sprites - Movement speed penalty on casting abilities instead of fully stopping agent
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class UIKeyBinder : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject UI;
|
|
[SerializeField] private GameKey key;
|
|
[SerializeField] private GameInputBinding gamepadBinding; // New field for gamepad binding
|
|
|
|
public UnityEvent<bool> OnUIVisibilityChanged = new UnityEvent<bool>();
|
|
|
|
|
|
bool isInputTriggered;
|
|
void Update()
|
|
{
|
|
if (GameStateController.Instance.CurrentState != GameState.GameScene) return;
|
|
|
|
// Check for input using both keyboard and gamepad
|
|
isInputTriggered =
|
|
(key != null && Input.GetKeyDown(key.keyCode)) ||
|
|
(!string.IsNullOrEmpty(gamepadBinding?.bindingName) && GameInputManager.Instance.GetButtonDown(gamepadBinding?.bindingName));
|
|
|
|
if (isInputTriggered)
|
|
{
|
|
UI.SetActive(!UI.activeSelf);
|
|
OnUIVisibilityChanged.Invoke(UI.activeSelf);
|
|
}
|
|
}
|
|
|
|
// Optional: Method to set gamepad binding name dynamically
|
|
public void SetGamepadBindingName(string bindingName)
|
|
{
|
|
gamepadBinding.bindingName = bindingName;
|
|
}
|
|
|
|
// Optional: Direct method to toggle UI if needed
|
|
public void ToggleUI()
|
|
{
|
|
UI.SetActive(!UI.activeSelf);
|
|
OnUIVisibilityChanged.Invoke(UI.activeSelf);
|
|
}
|
|
} |