代理,delegate,用法如下:
using UnityEngine;
using UnityEngine.Events;
namespace GFrame
{
/// <summary>
///
/// author: Gong
/// </summary>
public class GInteract
{
public delegate void CallBackSetValue(bool value);
public CallBackSetValue callbackSetValue;
public void Do()
{
callbackSetValue?.Invoke(true);
}
private static GInteract __inst;
public static GInteract Instance
{
get
{
if (null == __inst)
{
__inst = new GInteract();
}
return __inst;
}
}
}
}
在其他类中这样调用:
private void exFunc()
{
GInteract.Instance.callbackSetValue = _CallBack;
GInteract.Instance.Do();
}
private void _CallBack(bool value)
{
}

本文详细介绍了Unity中的GInteract类,展示了如何使用delegate回调机制来实现交互。通过实例说明了如何在GInteract的Do方法中调用回调函数,并在其他类中设置和触发回调。适合理解委托和事件处理的开发者学习。
3万+

被折叠的 条评论
为什么被折叠?



