44 lines
955 B
C#
44 lines
955 B
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class ModelButtonController : MonoBehaviour
|
|
{
|
|
// 按钮类型
|
|
//public ButtonType buttonType;
|
|
|
|
// 存储按钮点击事件
|
|
public UnityEvent onClickEvent;
|
|
private MyKeyBend keyBend;
|
|
|
|
void Start()
|
|
{
|
|
//onClickEvent = new UnityEvent();
|
|
if(GetComponent<MyKeyBend>()!=null)
|
|
keyBend=GetComponent<MyKeyBend>();
|
|
}
|
|
|
|
// 鼠标点击时触发
|
|
void OnMouseDown()
|
|
{
|
|
// 执行绑定的事件
|
|
onClickEvent?.Invoke();
|
|
if (keyBend != null)
|
|
keyBend.OnKeyPress();
|
|
Debug.Log("点击");
|
|
}
|
|
|
|
// 设置按钮点击事件
|
|
public void SetOnClickEvent(UnityAction action)
|
|
{
|
|
// 清除原来的事件,并绑定新的事件
|
|
//if (onClickEvent != null)
|
|
onClickEvent.RemoveAllListeners();
|
|
onClickEvent.AddListener(action);
|
|
}
|
|
|
|
public void ClearAllEvent()
|
|
{
|
|
onClickEvent.RemoveAllListeners();
|
|
}
|
|
}
|