Entity System Architecture with Unity - Unite Europe 2015
Entitas - open source Entity Component System for C# and Unity: https://github.com/sschmid/Entitas-CSharp
19. Create Blocker Entity
public static Entity CreateBlocker(this Pool pool, int x, int y)
{
return pool.CreateEntity()
.IsGameBoardElement(true)
.AddPosition(x, y)
.AddResource(Res.Blocker);
}
23. +------------------+
| Pool |
|------------------|
| e e | +-----------+
| e e---|----> | Entity |
| e e | |-----------|
| e e e | | Component |
| e e | | | +-----------+
| e e | | Component-|----> | Component |
| e e e | | | |-----------|
| e e e | | Component | | Data |
+------------------+ +-----------+ +-----------+
|
|
| +-------------+
| | e | Groups
| | e e |
+---> | +------------+
| e | | |
| e | e | e |
+--------|----+ e |
| e |
| e e |
+------------+
32. Render Position System
public class RenderPositionSystem : IReactiveSystem {
public IMatcher GetTriggeringMatcher() {
return Matcher.AllOf(Matcher.View, Matcher.Position);
}
public GroupEventType GetEventType() {
return GroupEventType.OnEntityAdded;
}
public void Execute(Entity[] entities) {
foreach (var e in entities) {
var pos = e.position;
e.view.gameObject.transform.position = new Vector3(pos.x, pos.y);
}
}
}
50. Advantages
• Straightforward to achieve Determinism and therefore
Replay
• Simulation Speed (2x, 4x)
• Headless Simulation, just remove systems which rely on
GameObjects (render systems)
• Save Game (Serialization / Deserialization) send data to
backend on change
• For us it replaced all OO Design Patterns