Unity3D NotificationCenter
来源:互联网 发布:ubuntu 17.10 qq 编辑:程序博客网 时间:2024/05/24 06:50
NotificationCenter封装了Unity3D的Message机制,直接将 NotificationCenter.cs 脚本拖到项目中就可以用了,
我们建立三个游戏对像A ,B,C,然后分别赋予它们脚本AS,BS,CS,这三个脚本中的内容如下AS BS CS:
void start(){ NotificationCenter.DefaultCenter.AddObserver(this,"AreYouOk");} void AreYouOk(){ Debug.Log("i am Ok --->" + transform.name);}
然后再建立一个脚本Caller.cs
void Start(){ NotificationCenter.DefaultCenter.PostNotification(this,"AreYouOk");}
建立一个游戏对象,并将Caller.cs赋予之,
现在运行游戏,Console中打印中三条信息,分别是
i am ok ---> A
i am ok ---> B
i am ok ---> C
NotificationCenter.DefaultCenter.AddObserver(this,"AreYouOk");意思是添加一个监听,我的理解是监听本代码文件中的AreYouOk函数,
当有一个脚本PostNotification的时候,所有的监听者都会得到Post,然后调用自己脚本中相应的函数
- Unity3D NotificationCenter
- NotificationCenter
- NotificationCenter
- NotificationCenter
- unity3d消息机制研究之二--------javascript 的 NotificationCenter
- NotificationCenter(简介)
- NotificationCenter(实战)
- cocos2d-x NotificationCenter
- NotificationCenter的基本使用
- NotificationCenter观察模式
- NotificationCenter、KVO、Delegate
- 本地通知 NotificationCenter
- 【Unity3D技巧】在Unity中使用事件/委托机制(event/delegate)进行GameObject之间的通信 (二) : 引入中间层NotificationCenter
- NotificationCenter KVC KVO Delegate 区别
- Cocos2d-x-------------------------------消息机制NotificationCenter
- Swift: NotificationCenter 用法 --- swift3.0
- poco库学习笔记(10) Poco::NotificationCenter
- Cocos2dx NotificationCenter(广播或通告)的使用方法
- 简单安装NFS流程
- 最小圆覆盖
- 作业4
- 如何读取配置文件数据
- 页游项目开发中的一些经验和教训
- Unity3D NotificationCenter
- 绘制矩形(方法二、空心的)
- TI 6678第四天 关于执行 .out文件
- TI 6678第三天 低版本工程导入高版本时候
- iOS 5与iOS 6的 low-memory 处理
- 使用GDAL将下载的Google卫星图像转为带坐标的tif
- 解决MFC中CListCtrl(virtual)控件闪烁问题
- zoj 2520 (暴力,恋爱数)
- TI 6678第一天