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

34 lines
768 B
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
{
public class KeyBind : MonoBehaviour
{
[SerializeField] public string keyName;
[SerializeField] public bool isPic = false;
[SerializeField] public Image image;
public Action<string> onClickAction;
private void Awake()
{
if (isPic)
{
image.gameObject.SetActive(true);
}
else
{
// GetComponentInChildren<TMP_Text>().text = keyName;
}
GetComponent<Button>().onClick.AddListener(OnClick);
}
private void OnClick()
{
onClickAction?.Invoke(keyName);
}
}
}