Creating the cards: an introduction to ECS systems, part 2
The next system we are going to write is the one responsible for creating the 54 cards that form the game's dungeon deck. We name this system CardCreationSystem and define it as follows:
Note the use of the entity manager's CreateArchetype method to create the entity archetypes. This method takes a list of the component types that define the archetype.
Finally, we use several helper methods to create our 54-card dungeon deck:
- 19 monster cards
- 6 sword cards
- 6 shield cards
- 9 potion cards
- 9 coin cards
- 5 ability cards
The specific numbers are the ones used in the original Card Crawl game; you can find the details here. Nothing fancy in this part of the code; we just set the data of the created entities as appropriate.
At this point, you can already run this code; just hit Play in the Unity editor and open the Entity Debugger option located in the Window/Analysis menu:
As you can see, there is no additional setup to make our ECS systems run; they are automatically picked up by Unity.
In the entity debugger, you can see which systems (some of them are predefined ones that come with the ECS) and entities are running. You can even selectively disable certain systems and inspect the details of any particular entity. Pretty cool!
It is expected that, as the ECS matures, a full-fledged integration with the Unity editor similar to the one that already exists for GameObjects and MonoBehaviours will be added to the engine.