官术网_书友最值得收藏!

Message processing

The final requirement for our Messaging System is that this object should have some kind of timing-based mechanism built in to prevent it from choking on too many messages at once. This means that, somewhere in the codebase, we will need to make use of MonoBehaviour event callbacks to tell our Messaging System to perform work during Unity's Update(), essentially enabling it to count time.

This could be achieved with the Static Class Singleton (which we defined earlier), which would require some other MonoBehaviour-based God Class to call into it, informing it that the Scene has been updated. Alternatively, we can use the Singleton Component to achieve the same thing, which has its own means of determining when Update() is called, and hence handle its workload independently of any God Class. The most notable difference between the two approaches is whether or not the system is dependent on the control of other objects and the various pros and cons of managing a Singleton Component (such that it won’t get destroyed between scenes; we don’t want to accidentally recreate it during shutdown).

The Singleton Component approach is probably the best, since there aren't too many occasions where we wouldn't want this system acting independently, even if much of our game logic depends upon it. For example, even if the game was paused, we wouldn't want the game logic to pause our Messaging System. We still want the Messaging System to continue receiving and processing messages so that we can, for example, keep UI-related Components communicating with one another while the gameplay is in a paused state.

主站蜘蛛池模板: 轮台县| 福海县| 富阳市| 南投县| 新巴尔虎右旗| 图们市| 宁南县| 班玛县| 靖远县| 安西县| 陆良县| 桃江县| 陆良县| 建瓯市| 海盐县| 贞丰县| 余江县| 余江县| 沽源县| 双流县| 南汇区| 长宁县| 昌图县| 鄯善县| 宣化县| 日土县| 沁水县| 社旗县| 若尔盖县| 高尔夫| 当雄县| 虎林市| 德格县| 汾西县| 宁都县| 永新县| 牡丹江市| 神农架林区| 余庆县| 韩城市| 昆明市|