c# event Action 判断事件列表中是否存在这个委托
using UnityEngine; using System.Collections; using System; public class eventTest : MonoBehaviour { private event Action<uint> onClick; private uint i = 0; // Use this for initialization void Start () { onClick += OnClick; onClick += OnClick; onClick += OnClick; onClick += OnClick; onClick += OnClick; onClick += OnClick; onClick += OnClick2; } // Update is called once per frame void Update () { if (Input.GetMouseButtonUp(0)) { Delegate[] list = onClick.GetInvocationList(); Debug.Log("存在在" + Array.IndexOf(list, (Action<uint>)OnClick2)); //for (int i = 0; i < list.Length; i++ ) //{ // if(list[i].Equals((Action<uint>)OnClick)) // { // } //} } } private void OnClick(uint i) { Debug.Log(i); i++; } private void OnClick2(uint i) { } }
不存在输出为-1,存在输出为大于0的index