Framwork/Assets/Scripts/Base/Keyboard/KeyBind.cs

48 lines
1.1 KiB
C#
Raw Normal View History

2025-06-04 22:49:37 +08:00
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace HK.Keyboard
{
2025-07-14 19:29:10 +08:00
public enum KeyType
{
None,
Number,
}
2025-06-04 22:49:37 +08:00
public class KeyBind : MonoBehaviour
{
[SerializeField] public string keyName;
[SerializeField] public bool isPic = false;
[SerializeField] public Image image;
2025-07-14 19:29:10 +08:00
[SerializeField] public KeyType keyType = KeyType.None;
private Button button;
2025-06-04 22:49:37 +08:00
public Action<string> onClickAction;
private void Awake()
{
if (isPic)
{
image.gameObject.SetActive(true);
}
else
{
// GetComponentInChildren<TMP_Text>().text = keyName;
}
2025-07-14 19:29:10 +08:00
button = GetComponent<Button>();
button.onClick.AddListener(OnClick);
2025-06-04 22:49:37 +08:00
}
private void OnClick()
{
onClickAction?.Invoke(keyName);
}
2025-07-14 19:29:10 +08:00
public void SetInteractable(bool isInteractable)
{
button.interactable = isInteractable;
}
2025-06-04 22:49:37 +08:00
}
}