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

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


原文地址:https://www.cnblogs.com/blfshiye/p/5280111.html