-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Generate your first component
Let's create our first custom component and let the Code Generator do its magic!
Open the Entitas preferences and set the Generated Folder
path where the Code Generator should save files.
Create a new class and implement IComponent
using Entitas;
public class PositionComponent : IComponent {
public float x;
public float y;
public float z;
}
Select Entitas/Generate
Create some Systems. Passing your contexts into these systems when you create them lets you create and edit entities and components within your systems. You can use any of the following commands within your systems to manipulate entities and components.
// create a new entity in the [Game] context
var e = contexts.game.CreateEntity();
// add a position component to it
// ReactiveSystems with GameMatcher.Position will receive this entity now
e.AddPosition(x, y, z);
// change the position
// ReactiveSystems with GameMatcher.Position again receive this entity
e.ReplacePosition(x, y, z);
// remove the position component from the entity
e.RemovePosition();
// delete the entity
e.Destroy();
Create a GameController script and attach it to an empty GameObject in your scene
public class GameController : Monobehaivour {
void Start() {
var contexts = Contexts.sharedInstance;
_systems = createSystems(contexts);
_systems.Initialize();
}
void Update() {
_systems.Execute();
_systems.Cleanup();
}
void OnDestroy() {
_systems.TearDown();
}
Systems createSystems(Contexts contexts) {
return new Feature("Systems")
// here is where you'd add your created systems
.Add(new MySystem(contexts))
.Add(new MyOtherSystem(contexts));
}
}
For more code examples see Code Generator
Guides: Introduction - Installation - Upgrading - FAQ - Cookbook - Contributing
Need Help? Ask a question on Discord or create an issue.
- The Basics
- Concepts
- Architecture / Patterns