Need help with ecsrx?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

EcsRx
299 Stars 28 Forks MIT License 329 Commits 4 Opened issues

Description

A reactive take on the ECS pattern for .net game developers

Services available

!
?

Need anything else?

Contributors list

EcsRx / SystemsRx

EcsRx is a reactive take on the common ECS pattern with a well separated design using rx and adhering to IoC and other sensible design patterns, with a more cut down systems only version called SystemsRx if you dont need Entities and Components.

Build Status Code Quality Status License Nuget Version Join Discord Chat Documentation

Features

  • Simple ECS interfaces to follow
  • Fully reactive architecture
  • Favours composition over inheritance
  • Adheres to inversion of control
  • Lightweight codebase
  • Built in support for events (raise your own and react to them)
  • Built in support for pooling (easy to add your own implementation or wrap 3rd party pooling tools)
  • Built in support for plugins (wrap up your own components/systems/events and share them with others)

The core framework is meant to be used primarily by .net applications/games, there is a unity specific version here which builds on top of this core version, as well as a monogame game version here.

Installation

The library was built to support .net standard 2.0, so you can just reference the assembly, and include a compatible rx implementation.

Quick Start

It is advised to look at the setup docs, this covers the 2 avenues to setup the application using it without the helper libraries, or with the helper libraries which offer you dependency injection and other benefits.

If you are using unity it is recommended you just ignore everything here and use the instructions on the ecsrx.unity repository as that has not been fully mapped over to use this core version yet so is its own eco system until that jump is made.

Simple components

public class HealthComponent : IComponent
{
    public int CurrentHealth { get; set; }
    public int MaxHealth { get; set; }
}

You implement the

IComponent
interface which marks the class as a component, and you can optionally implement
IDisposable
if you want to dispose stuff like so:
public class HealthComponent : IComponent, IDisposable
{
    public ReactiveProperty CurrentHealth { get; set; }
    public int MaxHealth { get; set; }

public HealthComponent() 
{ CurrentHealth = new ReactiveProperty<int>(); }

public void Dispose() 
{ CurrentHealth.Dispose; }

}

Any component which is marked with

IDisposable
will be auto disposed of by entities.

Simple systems

public class CheckForDeathSystem : IReactToEntitySystem
{
    public IGroup TargetGroup => new Group(typeof(HealthComponent)); // Get any entities with health component

public IObservable<ientity> ReactToEntity(IEntity entity) // Explain when you want to execute
{
    var healthComponent = entity.GetComponent<healthcomponent>();
    return healthComponent.CurrentHealth.Where(x =&gt; x &lt;= 0).Select(x =&gt; entity);
}

public void Process(IEntity entity) // Logic run whenever the above reaction occurs
{
    entity.RemoveComponent<healthcomponent>();
    entity.AddComponent<isdeadcomponent>();
}

}

Systems are conventional, so there are many built in types like

IReactToEntitySystem
,
IReactToGroupSystem
,
IManualSystem
and many others, but you can read about them in the docs/systems, you can add your own conventional systems by extending
ISystem
and systems are handled for you by the
ISystemExecutor
.

Check the examples for more use cases, and the unity flavour of ecsrx which has more examples and demo projects, and drop into the discord channel to ask any questions.

Running Examples

If you want to run the examples then just clone it and open examples project in the

src
folder, then run the examples, I will try to add to as the library matures.

There are also a suite of tests which are being expanded as the project grows, it was written with testability in mind.

Architecture / Infrastructure

MicroRx

This is a bare bones rx implementation, it literally just contains some basic

Subject
and other related rx classes, this is so that we do not have a dependencies on rx.net or unirx in the core.

SystemsRx

SystemsRx is a really just the Systems aspect of the ECS paradigm without any dependencies on Entites or Components. It allows you create your own conventions for systems as well as make use of the infrastructure layer which provides a DI abstraction layer, Plugin support and some best practice classes.

The 2 main libraries here are SystemsRx and SystemsRx.Infrastructure, these only have a dependency on MicroRx

EcsRx

This is layered on top of SystemsRx and adds the ECS paradigm to the framework as well as adding a couple of systems specifically for entity handling. This also contains an EcsRx.Infrastructure layer which builds off the SystemsRx.Infrastructure layer to provide additional ECS related infrastructure.

EcsRx.Plugins.*

These are plugins that can be used with EcsRx to add new functionality to the library, from entity persistance/rehydration to schedulable systems, these can optionally be added to your projects.

History

The library was originally deveoped for unity (way before they had their own ECS framework) and since then has moved to be a regular .net library that can run anywhere (Even in Blazor WASM).

Docs

There is a book available which covers the main parts which can be found here:

Documentation

This is basically just the docs folder in a fancy viewer

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.