一、回顾前面写的关于Delegate的消息传送优化文章,http://blog.csdn.net/chiuan/article/details/7883449
下面的代码是做一个简单的Delegate和SendMessage之间的优化性能差距测试:
using UnityEngine;
using System.Collections;
/// <summary>
/// Delegate basic.
/// just test Delegate && SendMessage ..
///
/// By Chiuan 2012.8
/// </summary>
public class DelegateBasic : MonoBehaviour {
//define my delegate statement.
public delegate void MyDelegate(string arg1);
//create my delegate object
public MyDelegate myDelegate;
//need some values to debug time spent.
bool isStart;
float timeStart;
int count;
bool isStartSendMessage;
// Use this for initialization
void Start () {
myDelegate += myFunciton1;
//myDelegate += myFunciton2;
}
// Update is called once per frame
void Update () {
if(isStart )
{