UnityEvent Unity事件

class in UnityEngine.Events

/

Inherits from:Events.UnityEventBase

/

Implemented in:UnityEngine.CoreModule

UnityEngine.Events 中的类

/

基础自:Events.UnityEventBase

/

实现于:UnityEngine.CoreModule

Description 描述

A zero argument persistent callback that can be saved with the Scene.

一个零参数的持续回调,可以与场景一起保存。

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"); } }

Constructors 构造函数

unity事件 UnityEvent 构造器 Constructors

Public Methods 公共方法

添加监听器 AddListener 向UnityEvent添加一个非持续性监听器。 Add a non persistent listener to the UnityEvent.
调用 Invoke 调用所有已注册的回调(运行时和持续的)。 Invoke all registered callbacks (runtime and persistent).
移除监听器 RemoveListener 从UnityEvent中移除一个非持续性监听器。 Remove a non persistent listener from the UnityEvent.

Inherited Members 继承成员

Public Methods 公共方法

获取持续事件计数 GetPersistentEventCount 获取注册持续监听器的数量。 Get the number of registered persistent listeners.
获取持续方法名 GetPersistentMethodName 在索引处获取监听器的目标方法名。 Get the target method name of the listener at index index.
获取持续的目标 GetPersistentTarget 在索引处获取侦听器的目标组件。 Get the target component of the listener at index index.
移除所有监听器(s) RemoveAllListeners 从事件中移除所有非持续(即从脚本中创建的)监听器 Remove all non-persisent (ie created from script) listeners from the event.
设置持续监听器状态 SetPersistentListenerState 修改持续监听器的执行状态。 Modify the execution state of a persistent listener.

Static Methods 静态方法

获取有效的方法信息 GetValidMethodInfo 给定对象、函数名和参数类型列表;找到匹配的方法。 Given an object, function name, and a list of argument types; find the method that matches.