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

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.

主站蜘蛛池模板: 临洮县| 曲水县| 夏邑县| 武威市| 邛崃市| 佛山市| 南丰县| 鄂伦春自治旗| 关岭| 苏尼特右旗| 突泉县| 馆陶县| 北流市| 平凉市| 临澧县| 二连浩特市| 乌拉特前旗| 聂荣县| 乐东| 邵武市| 财经| 鄄城县| 文安县| 藁城市| 威信县| 孝感市| 崇左市| 察哈| 库伦旗| 磴口县| 通渭县| 清镇市| 台中市| 五指山市| 贵港市| 左权县| 抚宁县| 吴川市| 乌恰县| 蕉岭县| 廊坊市|