Skip to content

Repository files navigation

Coplt.Systems

Automatic system (the S in ECS) scheduling and dependency injection

Examples

[System]publicpartialclassSysGroup1:ISystemGroup;
public struct Data
{publicintinc;}[System]publicreadonlypartialstructSys1<T>(reffloata,intb)// di on constructor parameters{// di on partial propertiespublicpartialrefDataData{get;}publicpartialref readonly DataData2{get;}privatereadonlyfloatsome=a+b;publicvoidUpdate(refinta)// di on parameters{Data.inc++;}}// use// Build systemsvarsys=newSystems();sys.SetResource(newData());// Resources will be automatically dependency injectedsys.Add<Sys1<int>>();sys.Add<SysGroup1>();// Call update every framesys.Update();// Resources can be modified and retrieved at any time (thread-safe)varinc=sys.GetResource<Data>().inc;Console.WriteLine(inc);Assert.That(inc,Is.EqualTo(1));

Setting groups and order via attributes

[System(Group=typeof(SysGroup1))]publicreadonlypartialstructSys4{privatevoidUpdate(refDatadata)=>data.inc*=2;}[System(Group=typeof(SysGroup1),Before=[typeof(Sys4)])]publicreadonlypartialstructSys5{privatevoidUpdate(refDatadata)=>data.inc*=3;}[System(After=[typeof(SysGroup1)])]publicreadonlypartialstructSys6{privatevoidUpdate(refDatadata)=>data.inc+=3;}varsys=newSystems();sys.SetResource(newData{inc=6});sys.Add<SysGroup1>();sys.Add<Sys4>();sys.Add<Sys5>();sys.Add<Sys6>();sys.Update();varinc=sys.GetResource<Data>().inc;Console.WriteLine(inc);Assert.That(inc,Is.EqualTo(39));

Custom resource providers

publicclassNullResourceProvider:ResourceProvider<NullAttribute>{publicoverrideResRef<T>GetRef<T>(NullAttributedata,ResReqreq=default){Console.WriteLine(data.Msg);returndefault;}}[AttributeUsage(AttributeTargets.Parameter|AttributeTargets.Property)]publicsealedclassNullAttribute(stringMsg=""):ResourceProviderAttribute<NullResourceProvider,NullAttribute>{publicstringMsg{get;}=Msg;publicoverrideNullAttributeGetData()=>this;}[AttributeUsage(AttributeTargets.Parameter|AttributeTargets.Property)]publicsealedclassNullAttribute(stringMsg=""):ResourceProviderAttribute<NullResourceProvider>{publicstringMsg{get;}=Msg;}[System]publicpartialclassNullResourceProviderSystem([Null]object?a):ISystem{[Null("Some")]publicpartialobject?Some{get;set;}publicpartialobject?Foo{get;set;}publicvoidUpdate([Null]object?b){}}varsys=newSystems();sys.SetResourceProvider(newNullResourceProvider());sys.Add<NullResourceProviderSystem>();sys.Update();// print: Some

About

Automatic system (the S in ECS) scheduling and dependency injection

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages