更新
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user