using UnityEngine;
using UnityEngine.UI;
namespace QFramework.MJT
{
// 只要是继承这个父类都会帮它声明通用变量 以及 按钮点击的方法
public class MyBtnBase : MonoBehaviour
{
public Button currentBtn;
public GameObject childObj;
public void Awake()
{
currentBtn = GetComponent<Button>();
childObj = transform.GetChild(0).gameObject;
currentBtn.onClick.AddListener(() =>
{
ClickCurrentBtn();
});
}
protected void ClickCurrentBtn()
{
Debug.Log("父类通用按钮点击");
childObj.Show();
currentBtn.interactable = false;
}
}
}
using UnityEngine;
namespace QFramework.MJT
{
// 变量和按钮点击的通用属性都放到父类 特性由自己实现
public class FirstGameFloorBtn : MyBtnBase
{
// Start is called before the first frame update
void Start()
{
currentBtn.onClick.AddListener(() =>
{
Debug.Log("子类按钮点击");
});
}
}
}