53 lines
1.2 KiB
C#
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}";
|
|
}
|
|
}
|
|
} |