public class TextDelegate2{
public delegate void LogDelegate(string log); //定义 委托名为LogDelegate,带一个string参数的 委托类型
public static LogDelegate LogEvent; //声明委托对象,委托实例为LogEvent
public static void OnLogEvent(string log)
{
if (LogEvent != null)
{
LogEvent(log);
}
}
}
/// <summary>
/// 添加调用事件,调用委托
/// </summary>
class TextDelegate : MonoBehaviour
{
void Start()
{
TextDelegate2.LogEvent += Cat;
TextDelegate2.LogEvent += Dog;
TextDelegate2.OnLogEvent("给小动物发喂食物了");//给函数发送回调信息
}
void Cat(string log)
{
Debug.Log("喵喵喵:" + log);
}
void Dog(string log)
{
Debug.Log("汪汪汪:" + log);
}
}
public delegate void LogDelegate(string log); //定义 委托名为LogDelegate,带一个string参数的 委托类型
public static LogDelegate LogEvent; //声明委托对象,委托实例为LogEvent
public static void OnLogEvent(string log)
{
if (LogEvent != null)
{
LogEvent(log);
}
}
}
/// <summary>
/// 添加调用事件,调用委托
/// </summary>
class TextDelegate : MonoBehaviour
{
void Start()
{
TextDelegate2.LogEvent += Cat;
TextDelegate2.LogEvent += Dog;
TextDelegate2.OnLogEvent("给小动物发喂食物了");//给函数发送回调信息
}
void Cat(string log)
{
Debug.Log("喵喵喵:" + log);
}
void Dog(string log)
{
Debug.Log("汪汪汪:" + log);
}
}