- Unity Game Optimization
- Dr. Davide Aversa Chris Dickinson
- 178字
- 2021-06-24 12:13:05
Implementing custom messages
We've created the messaging system, but an example of how to use it would help us to wrap our heads around the concept. Let's start by defining a pair of simple classes that derive from Message, which we can use to create a new enemy, as well as to notify other parts of our code base that an enemy was created:
public class CreateEnemyMessage : Message {}
public class EnemyCreatedMessage : Message {
public readonly GameObject enemyObject;
public readonly string enemyName;
public EnemyCreatedMessage(GameObject enemyObject, string enemyName) {
this.enemyObject = enemyObject;
this.enemyName = enemyName;
}
}
CreateEnemyMessage is the simplest form of message that contains no special data, while EnemyCreatedMessage will contain a reference to the enemy's GameObject as well as its name. Good practice for message objects is to make their member variables not only public but also readonly. This ensures that the data is easily accessible but cannot be changed after the object's construction. This safeguards the content of our messages against being altered, as they're passed between one listener and another.
- Clojure Programming Cookbook
- 程序員面試筆試寶典(第3版)
- R語言數據分析從入門到精通
- MongoDB for Java Developers
- Raspberry Pi 2 Server Essentials
- 深度強化學習算法與實踐:基于PyTorch的實現
- Apache Mesos Essentials
- 精通MATLAB(第3版)
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- 詳解MATLAB圖形繪制技術
- App Inventor 2 Essentials
- 大學計算機基礎實訓教程
- Java EE 8 and Angular
- Python預測之美:數據分析與算法實戰(雙色)
- Visual Basic程序設計基礎