知识点
Delegate的GetInvocationList方法返回一个数组,该数组存储添加的方法
实例
using UnityEngine;
using UnityEngine.Events;
public class TestEvent : MonoBehaviour
{
UnityAction action;//无参无返回值 委托
event UnityAction eventAction;//事件
void Start()
{
action += Print;
action += Print;
//打印调用列表
foreach (var item in action.GetInvocationList())
{
Debug.Log(item.Method);//打印方法名
}
eventAction += Print;
eventAction += Print;
//打印调用列表
foreach (var item in eventAction.GetInvocationList())
{
item.Method.Invoke(this, null);//执行方法
}
}
void Print()
{
Debug.Log("123");
}
}