Version: 2022.1

UnityEvent

class in UnityEngine.Events

/

继承自:Events.UnityEventBase

切换到手册

描述

可以与场景一起保存的 zero 参数持久回调。

using UnityEngine;
using UnityEngine.Events;
using System.Collections;

public class ExampleClass : MonoBehaviour { UnityEvent m_MyEvent;

void Start() { if (m_MyEvent == null) m_MyEvent = new UnityEvent();

m_MyEvent.AddListener(Ping); }

void Update() { if (Input.anyKeyDown && m_MyEvent != null) { m_MyEvent.Invoke(); } }

void Ping() { Debug.Log("Ping"); } }

构造函数

UnityEvent构造函数。

公共函数

AddListener向 UnityEvent 添加非持久性监听器。
Invoke调用所有已注册的回调(运行时和持久性)。
RemoveListenerRemove a non persistent listener from the UnityEvent. If you have added the same listener multiple times, this method will remove all occurrences of it.

继承的成员

公共函数

GetPersistentEventCount获取已注册的持久性监听器的数量。
GetPersistentListenerStateReturns the execution state of a persistent listener.
GetPersistentMethodName获取索引处的监听器的目标方法名称。
GetPersistentTarget获取索引处的监听器的目标组件。
RemoveAllListeners从事件中删除所有非持久性(即通过脚本创建的)监听器。
SetPersistentListenerState修改持久性监听器的执行状态。

静态函数

GetValidMethodInfo提供了对象、函数名称和参数类型列表;找到匹配的方法。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961