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

【Unity3D自学记录】Unity3D代理委托模式

2014-05-29 09:56 295 查看
using UnityEngine;
using System.Collections;

public class DJH_Delegate : MonoBehaviour
{

public delegate void Delegate1();
public Delegate1 OutTest1;

public delegate void Delegate2(int index);
public Delegate2 OutTest2;

int index = 12345;
void Start()
{
OutTest1 = DebugLog1;
OutTest2 = DebugLog2;
}
void OnGUI()
{
//开始按钮
if (GUI.Button(new Rect(0, 10, 100, 30), "Button1"))
{
if (OutTest1 != null)//无参数
{
DebugLog1();
}
}
if (GUI.Button(new Rect(0, 60, 100, 30), "Button2"))
{
if (OutTest2 != null)//有参数
{
DebugLog2(index);
}
}
}

void DebugLog1()
{
Debug.Log("Button1");
}

void DebugLog2(int index)
{
Debug.Log("Button2参数:" + index);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d