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

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.

主站蜘蛛池模板: 合水县| 鄂伦春自治旗| 墨竹工卡县| 个旧市| 田阳县| 贵溪市| 泰州市| 巴马| 华容县| 宣恩县| 交口县| 稻城县| 涟水县| 泽普县| 常宁市| 东乌| 郁南县| 顺平县| 东源县| 印江| 浦城县| 铜川市| 准格尔旗| 成都市| 庄浪县| 衢州市| 张家界市| 阿鲁科尔沁旗| 枝江市| 囊谦县| 营山县| 沙湾县| 林口县| 涟源市| 定日县| 绥德县| 江孜县| 雷波县| 洱源县| 祁阳县| 建水县|