48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace HK.Keyboard
|
|
{
|
|
public enum KeyType
|
|
{
|
|
None,
|
|
Number,
|
|
}
|
|
|
|
public class KeyBind : MonoBehaviour
|
|
{
|
|
[SerializeField] public string keyName;
|
|
[SerializeField] public bool isPic = false;
|
|
[SerializeField] public Image image;
|
|
[SerializeField] public KeyType keyType = KeyType.None;
|
|
private Button button;
|
|
public Action<string> onClickAction;
|
|
|
|
private void Awake()
|
|
{
|
|
if (isPic)
|
|
{
|
|
image.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
// GetComponentInChildren<TMP_Text>().text = keyName;
|
|
}
|
|
|
|
button = GetComponent<Button>();
|
|
button.onClick.AddListener(OnClick);
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
onClickAction?.Invoke(keyName);
|
|
}
|
|
|
|
public void SetInteractable(bool isInteractable)
|
|
{
|
|
button.interactable = isInteractable;
|
|
}
|
|
}
|
|
} |