用法简介 1 代表第一种方法 2代表第二种方法,还有一点比较方便的是非必要可以不用每次都要写移除监听的方法,因为继承了Mono,会自动管理的,如果要传多个参数就在DeSubscribe这里写你需要的参数 比如 DeSubscribe 接收和传递都参数同步就行,刚开始用的时候可以参考复制下面脚本的方法注意引用命名空间,遇到问题就评论
using NKGame.Common.EvnetSystem;
public class NewBehaviourScript : MonoBehaviour
{
public Button btn;
void Start()
{
//1 监听
MonoEventManager.Subscribe(gameObject,LogicEventType.AddCaijiAwardAnimation,UIMaxLayer_Change);
//2 监听
LogicEvnetSystem.Subscribe(LogicEventName.ActivityWorldBoss,LogicEventName.GROUP_UI, UIMaxLayer_Change3);
//2 传参
MonoEventManager.Subscribe(gameObject, LogicEventName.LabaBigGiftView_RefreshData, LogicEventName.GROUP_UI, UIMaxLayer_Change2);
btn.onClick.AddListener(() => {
//1 通知
LogicEvnetSystem.Publish(LogicEventType.AddCaijiAwardAnimation);
//1 移除
LogicEvnetSystem.RemoveSubScribe(LogicEventType.AddCaijiAwardAnimation, UIMaxLayer_Change);
//2 通知
LogicEvnetSystem.Publish(LogicEventName.ActivityWorldBoss, LogicEventName.GROUP_UI);
//2 传参通知
LogicEvnetSystem.Publish(LogicEventName.LabaBigGiftView_RefreshData, LogicEventName.GROUP_UI,"2传参通知");
//2 移除
LogicEvnetSystem.DeSubscribe(LogicEventName.ActivityWorldBoss, LogicEventName.GROUP_UI, UIMaxLayer_Change3);
//2 传参移除
LogicEvnetSystem.DeSubscribe(LogicEventName.LabaBigGiftView_RefreshData, LogicEventName.GROUP_UI, UIMaxLayer_Change2);
; });
}
public void UIMaxLayer_Change(LogicEventType e, object[] t)
{
Debug.LogError("枚举通知");
}
public void UIMaxLayer_Change2( string t)
{
Debug.LogError("name传参"+t);
}
///
/// 无参数
///
public void UIMaxLayer_Change3()
{
Debug.LogError("无参数name通知");
}
2021-10-13 13:08:55
15KB
开发工具
1