Sw1f1Ecs 0.4.3

dotnet add package Sw1f1Ecs --version 0.4.3
                    
NuGet\Install-Package Sw1f1Ecs -Version 0.4.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sw1f1Ecs" Version="0.4.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sw1f1Ecs" Version="0.4.3" />
                    
Directory.Packages.props
<PackageReference Include="Sw1f1Ecs" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sw1f1Ecs --version 0.4.3
                    
#r "nuget: Sw1f1Ecs, 0.4.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sw1f1Ecs@0.4.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sw1f1Ecs&version=0.4.3
                    
Install as a Cake Addin
#tool nuget:?package=Sw1f1Ecs&version=0.4.3
                    
Install as a Cake Tool

Sw1f1Ecs - C# Entity Component System framework

Content

API

Worlds

Create world

IWorld world1 = WorldBuilder.Build();

Destroy world

world.Destroy();

Components

public struct Component1 : IComponent {
    public int Value;

    public Component1(int value) {
            Value = value;
    }
}

IAutoResetComponent is needed to create a new component with already defined variables

public struct Component2 : IComponent, IAutoResetComponent<Component2>, {
    public int Value;

    public Component2(int value) {
        Value = value;
    }

    public void Reset(ref Component2 c) {
        c.Value = 1;
    }
}

IAutoCopyComponent is needed to copy a component from one entity to another

public struct Component3 : IComponent, IAutoCopyComponent<Component3>, {
    public int Value;

    public Component3(int value) {
        Value = value;
    }

    public void Copy(ref Component3 src, ref Component3 dst) {
        dst.Value = src.Value;
    }
}

Entities

Entities can only be created with a component. When the last component is deleted, the entity is deleted too.

Entity entity = world.CreateEntity<IsTestEntity>();
//adding a new component
entity.Add(new Component1());

//take component
ref Component1 c1 = ref entity.Get<Component1>();

//create a new one and take or take an already created component from the entity (may use IAutoResetComponent)
ref Component2 c2 = ref entity.GetOrSet<Component2>();

//check for component presence
bool isHasComponent2 = entity.Has<Component2>();

//removing a component from an entity
entity.Remove<Component1>();

Copying an entity creates a new entity with the same components. Copying a component can be configured using the IAutoCopyComponent interface.

var copy = entity1.Copy();

Filters

Filters maintain a list of all entities with certain components

//contains entities with component Component1
var filter1 = world.GetFilter(new FilterMask<Component1>());

//contains entities with components Component1, Component2 and without component Component3
var filter2 = world.GetFilter(new FilterMask<Component1,Component2>.Exclude<Component3>());

//contains entities with component Component1 and without component Component3
var filter3 = world.GetFilter(new FilterMask<Component1>.Exclude<Component3>());

foreach (Entity entity in filter1) {
    //any actions with the entity
}

Multithreaded filter for working with entities in different threads FilterThreadJob not support - set component, clone entity and create entity

private class Component1FilterThreadJob : FilterThreadJob {
    protected override void ExecuteInternal(Entity entity) {
        ref var c = ref entity.Get<Component1>();
        //any actions with the entity
    }
}
var filter = world.GetFilter(new FilterMask<Component1>());
var сomponent1FilterTread = new Component1FilterThreadJob();
сomponent1FilterTread.Execute(filter);

Systems

The IInitSystem interface is needed to initialize the system.

public sealed class TestInitSystem : IInitSystem {
    private WorldInject _worldInject = default;
        
    public void Init() {
        //any action
    }
}

The IUpdateSystem interface is needed to update the system

public sealed class TestUpdate2System : IUpdateSystem {
    private FilterInject<Include<Component1>, Exclude<Component2>> _filter = default;

    public void Update() {
        foreach (var entity in _filter.Value) {
            entity.Add(new Component2());   
        }
    }
}

Create systems. Supports 'Inject' data

IWorld world = WorldBuilder.Build();
Systems systems = new Systems(world);
systems
    .Add(new TestInitSystem())
    .Add(new TestUpdate1System())
    .Inject();

systems.Init();
systems.Update();

GroupSystems

public sealed class TestGroupSystems : IGroupSystem {
    public string GroupName => nameof(TestGroupSystems);
    public bool State => true;

    public ISystem[] Systems => new ISystem[] {
        new TestUpdate1System(),
        new TestSubGroupSystems(),
    };
}

public sealed class TestSubGroupSystems : IGroupSystem {
    public string GroupName => nameof(TestSubGroupSystems);
    public bool State => true;
    public ISystem[] Systems => new ISystem[] {
        new TestUpdate3System(),
    };
}

//disabling a group of systems TestSubGroupSystems
systems.SetActiveGroup(nameof(TestSubGroupSystems), false);

DI

Supports injection World/Filter/Systems/CustomData

public sealed class TestInjectSystem : IInitSystem, IUpdateSystem {
    private readonly WorldInject _world = default;
    private readonly FilterInject<Include<Component1, Component2>, Exclude<Component3>> _filterInject = default;
    private readonly SystemsInject _systemsInject = default;
    private readonly CustomInject<TestData> _testData = default;

    public void Init() { }
    public void Update() { }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.3 233 4/23/2025
0.4.2 150 4/12/2025
0.4.1 145 4/12/2025