您的位置:首页 > 移动开发 > Unity3D

【Unity3D】【NGUI】怎样动态给EventDelegate加入參数

2016-03-15 16:47 555 查看
NGUI讨论群:333417608

NGUI版本号:3.6.8

注意:參数必须是公共成员变量。不能是栈上的、或者私有的(就是暂时在函数里面定义的或者是函数的參数都不行)

using UnityEngine;
using System.Collections;

public class SZEventDelegateParams : MonoBehaviour {

public int param = 2;

void Start()
{
// 创建新的delegate,最后调用此(this)脚本的Finished函数。当然this能够换成别的脚本。这里为了方便
EventDelegate eventDelegate = new EventDelegate(this, "Finished");
// 把第一个參数设置为此(this)脚本的param变量。当然this能够换成别的脚本,这里为了方便
eventDelegate.parameters[0] = new EventDelegate.Parameter(this, "param");

UIPlayTween uipt = this.GetComponent<UIPlayTween>();
uipt.onFinished.Add(eventDelegate);
uipt.Play(true);
}

// PlayTween 结束后。会调用到这里,打印对应的值
void Finished(int p)
{
Debug.Log(p.ToString());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: