UnityEvent<T0, T1>
Two argument version of UnityEvent.
阅读时间1 分钟最后更新于 1 个月前
Definition
- Type: Class
- Namespace: UnityEngine.Events
- Assembly: UnityEngine.CoreModule
- Inherits from: UnityEventBase
- Implements: ISerializationCallbackReceiver
public class UnityEvent<T0, T1> : UnityEventBase, ISerializationCallbackReceiver
Remarks
Generics are supported, specify type parameters on initialization as shown in the example. Refer to Configure callbacks in the Inspector for details on configuring callbacks in the Inspector window.
using UnityEngine;using UnityEngine.Events;public class ExampleClass : MonoBehaviour{ UnityEvent<int, int> m_MyEvent; void Start() { if (m_MyEvent == null) m_MyEvent = new UnityEvent<int, int>(); m_MyEvent.AddListener(DoSomething); } void Update() { if (Input.anyKeyDown && m_MyEvent != null) { m_MyEvent.Invoke(5, 6); } } void DoSomething(int i, int j) { Debug.Log("Callback called " + i + ", " + j); }}
Note: UnityEvent can also be awaited in any async method.