Skip to content

Generate your first component

FNGgames edited this page Mar 17, 2017 · 13 revisions

Generate your first component

Let's create our first custom component and let the Code Generator do its magic!

Step 1

Open the Entitas preferences and set the Generated Folder path where the Code Generator should save files.

Entitas.Unity.CodeGenerator

Step 2

Create a new class and implement IComponent

using Entitas;

public class PositionComponent : IComponent {
    public float x;
    public float y;
    public float z;
}

Step 3

Select Entitas/Generate

Entitas.Unity.CodeGenerator

Step 4

Create a GameController script

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 Example Systems see [Systems] (https://github.com/sschmid/Entitas-CSharp/wiki/Systems).

For more code examples see Code Generator

Clone this wiki locally