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

  • Unity Game Optimization
  • Dr. Davide Aversa Chris Dickinson
  • 269字
  • 2021-06-24 12:13:05

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 code base, 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 would still want the messaging system to continue receiving and processing messages so that we could, for example, keep UI-related components communicating with one another while the gameplay is in a paused state.

主站蜘蛛池模板: 长寿区| 凤凰县| 富民县| 拜城县| 东阿县| 东明县| 和硕县| 革吉县| 长宁县| 迭部县| 安陆市| 巴林左旗| 松原市| 奉新县| 米林县| 泰顺县| 泽普县| 手机| 清河县| 西吉县| 聂拉木县| 长汀县| 宁波市| 曲阜市| 广西| 离岛区| 墨脱县| 五寨县| 磐安县| 莱芜市| 奇台县| 石渠县| 章丘市| 凤山市| 壤塘县| 宝鸡市| 白朗县| 汉中市| 泰安市| 宝清县| 霸州市|