ECS - code templates for Unity

Code generation is what I’m trying to avoid at all. But sometimes it can be useful, for example, to automate repeatable operations like creating ecs-system template or even ecs-startup behaviour.

Code generation is what I’m trying to avoid at all. But sometimes it can be useful, for example, to automate repeatable operations like creating ecs-system template or even ecs-startup behaviour.

Unity-Integration now supports generation of 5 types of code templates:

Startup template

Useful for fast creation of ready-to-use MonoBehaviour-based initialization of ECS world / systems with automatic debug visualization at scene:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Leopotam.Ecs;
using UnityEngine;

namespace Client {
sealed class TestEcsStartup : MonoBehaviour {
EcsWorld _world;
EcsSystems _systems;

void OnEnable () {
_world = new EcsWorld ();
#if UNITY_EDITOR
Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create (_world);
#endif
_systems = new EcsSystems (_world);
_systems
// Register your systems here, for example:
// .Add (new TestSystem1())
// .Add (new TestSystem2())
.Initialize ();
#if UNITY_EDITOR
Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create (_systems);
#endif
}

void Update () {
_systems.Run ();
}

void OnDisable () {
_systems.Dispose ();
_systems = null;
_world.Dispose ();
_world = null;
}
}
}

Init system template

Useful for fast creation of ready-to-use IEcsInitSystem class:

1
2
3
4
5
6
7
8
9
10
11
using Leopotam.Ecs;

namespace Client {
sealed class TestEcsInitSystem : IEcsInitSystem {
void IEcsInitSystem.Initialize () {
// Add your initialize code here.
}

void IEcsInitSystem.Destroy () { }
}
}

Run system template

Useful for fast creation of ready-to-use IEcsRunSystem class:

1
2
3
4
5
6
7
8
9
using Leopotam.Ecs;

namespace Client {
sealed class TestEcsRunSystem : IEcsRunSystem {
void IEcsRunSystem.Run () {
// Add your run code here.
}
}
}

Common component template

Standard component class:

1
2
3
4
5
namespace Client {
sealed class TestEcsComponent {
// Add your data here.
}
}

No-data component template

Component without data and “working as flag” class:

1
2
3
4
5
6
using Leopotam.Ecs;

namespace Client {
[EcsIgnoreInFilter]
sealed class TestEcsComponentFlag { }
}

Custom namespace support

All templates supports custom namespace declaration (“Client” by default), it can be change from Editor Settings (“Root namespace” property):