[Unity3D]在游戏开发中Notification Center的简单使用与案例说明

本文介绍了Unity3D的Notification Center在游戏开发中的简单使用,包括鼠标碰撞检测和事件监听。通过示例说明了如何进行数据传输和处理类型转换问题,以解决实际场景中的需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习Unity脚本推荐:Unity3D官网索引


Notification Center,顾名思义,就是用来处理各种通知的信息中心。

Unity3D的官网解释如下:

Notification Center的脚本源码如下:

import System.Collections.Generic;

//    NotificationCenter is used for handling messages between GameObjects.
   
//    GameObjects can register to receive specific notifications.  When another objects sends a notification of that type, all GameObjects that registered for it and implement the appropriate message will receive that notification.
   
//    Observing GameObjetcs must register to receive notifications with the AddObserver function, and pass their selves, and the name of the notification.  Observing GameObjects can also unregister themselves with the RemoveObserver function.  GameObjects must request to receive and remove notification types on a type by type basis.
   
//    Posting notifications is done by creating a Notification object and passing it to PostNotification.  All receiving GameObjects will accept that Notification object.  The Notification object contains the sender, the notification type name, and an option hashtable containing data.

//    To use NotificationCenter, either create and manage a unique instance of it somewhere, or use the static NotificationCenter.


// We need a static method for objects to be able to obtain the default notification center.
// This default center is what all objects will use for most notifications.  We can of co
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值