- 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.
- DevOps with Kubernetes
- 深入理解Bootstrap
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- Java面向對象軟件開發
- Django開發從入門到實踐
- 高級C/C++編譯技術(典藏版)
- Cassandra Data Modeling and Analysis
- 深度強化學習算法與實踐:基于PyTorch的實現
- 精通Python設計模式(第2版)
- HTML5從入門到精通 (第2版)
- Mastering Business Intelligence with MicroStrategy
- 深入解析Java編譯器:源碼剖析與實例詳解
- UX Design for Mobile
- Go Systems Programming
- ANSYS FLUENT 16.0超級學習手冊