Files
aibis-dream/Assets/Scripts/MiniGame/BlockPuzzle/Class/ShapeCreateButton.cs
T
2025-12-08 19:54:35 +08:00

53 lines
1.2 KiB
C#

using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream
{
[RequireComponent(typeof(Button))]
public class ShapeCreateButton : MonoBehaviour
{
[SerializeField] private Button button;
[SerializeField] private TMP_Text text;
private string blockShapeKey;
private int count;
public event Action<string> OnClick;
private void Awake()
{
GetComponent<Button>().onClick.AddListener(OnButtonClick);
}
private void OnDestroy()
{
GetComponent<Button>().onClick.RemoveListener(OnButtonClick);
}
public void OnButtonClick()
{
if (count > 0)
{
OnClick?.Invoke(blockShapeKey);
count--;
text.text = $"{blockShapeKey}: {count}";
}
}
public void SetButtonInfo(string key, int count)
{
blockShapeKey = key;
this.count = count;
text.text = $"{key}: {count}";
gameObject.name = key;
}
public void AddCount()
{
count++;
text.text = $"{blockShapeKey}: {count}";
}
}
}