A simple C# Entity Component System. This library aims to simplify and speed up the implementation of ECS in C# games and engines.
- Actors (entities) are integers and hold no data
- Components are simple structs and are stored in contiguous memory
- A view system that allows you to query actors during runtime
- A System implementation that allows you to process entities based on their components
It's very easy to start using this library. Simply add it as a reference to your project. To start using it in code, you have to initialize an ActorRegistry
:
const int maxActors = 10000;
ActorRegistry actorRegistry = new ActorRegistry(maxActors);
int actor = actorRegistry.CreateActor();
struct CoolComponent {
public int coolness;
}
actorRegistry.RegisterComponent<CoolComponent>();
actorRegistry.AddComponent<CoolComponent>(actor);
bool isCool = actorRegistry.HasComponent<CoolComponent>(actor);
actorRegistry.RemoveComponent<CoolComponent>(actor);
ActorView coolView = actorRegistry.CreateView<CoolComponent>();
Console.WriteLine(coolView.Count);
A System can be any class that inherits from ActorSystem
public RenderSystem : ActorSystem {
void CoolFunc() {
//Access actors with //this.Actors
}
}
RenderSystem renderSystem = actorRegistry.RegisterSystem<CoolComponent, RenderingComponent>()
You can find more examples in the Unit Tests