Here you'll find some helper utils for Morpeh ECS framework.
THIS IS NOT PART OF MORPEH ECS, JUST FEW HELPERS BY ME, USE IT AT YOUR OWN RISK
The minimal checked Unity Version is 2020.3.* LTS
Also, make sure you've already installed Morpeh, either you'll get compiler errors.
Open Package Manager and "Add package from git url..." using next string:
https://github.com/SH42913/morpeh.helpers.git?path=/Assets/Morpeh.Helpers
filter.RemoveAllEntities()
to remove all entities in filterfilter.RemoveComponentForAll<T>()
to remove component of type T from all entities in filterentity.Exists()
to make sure entity is not null and not disposed (marked as Obsolete, useentity.IsNullOrDisposed()
instead)entity.GetOrCreate<T>()
to get component of type T if it exists or create a new one (marked as Obsolete, useAddOrGet()
below instead)stash.AddOrGet(entity)
to get existed component or add new one to entity using Stashentity.AddOrGet()
to get existed component or add new one to Entity
They're abstract classes based on UpdateSystem, FixedUpdateSystem, or LateUpdateSystem. They'll let you reduce boilerplate in your code for simple systems, where you query through one filter with one/two/three components. No need to manually define the filter and iterate through that, just write your logic like you're processing one entity.
They leave you only one method to implement: Process(entity, ref c1(, ref c2)(, ref c3), deltaTime)
.
Process()
also will be called during OnAwake()
of system, you can use protected field inAwake
to branch your logic for this case.
Available classes:
SimpleUpdateSystem<T>
based onUpdateSystem
andSimpleSystem<T>
based onISystem
SimpleFixedUpdateSystem<T>
based onFixedUpdateSystem
andSimpleFixedSystem<T>
based onIFixedSystem
SimpleLateUpdateSystem<T>
based onLateUpdateSystem
andSimpleLateSystem<T>
based onILateSystem
- All variants can handle up to 3 generic parameters, eg
SimpleSystem<T1,T2,T3>
- You also can inherit non-generic abstract SimpleFixed/Late/UpdateSystem to implement your variation of Simple System
Example:
public sealed class HealingSystem : SimpleUpdateSystem<HealthComponent> {
public float healRate = 1f;
protected override void Process(IEntity entity, ref HealthComponent health, float deltaTime) {
health.amount += healRate * deltaTime;
}
}
aka Auto-clean systems
That util will let you register a type of component to clean up all existing components during LateUpdate(based on ICleanupSystem
in Morpeh). So you'll be able to write World.RegisterOneFrame<T>()
once and fire components without the need to clean up after you.
How to use that: Just call extension-method World.RegisterOneFrame<T>()
in OnAwake()
of your system to system's World property.
How to migrate from previous SO-based OneFrames
- Remove OneFrameCleanSystem from your Installer
- Remove ScriptableObject assets of previously created OneFrameRegistry and OneFrameCleanSystem
- Replace calls
oneFrameRegister.RegisterOneFrame<T>()
withWorld.RegisterOneFrame<T>()
If you're using JetBrains Rider, I also can offer Morpeh Templates for you.\
It contains:
- Morpeh System file template (based on ISystem or ScriptableObject)
- Morpeh Component file template
- Morpeh Provider file template
- Morpeh Provider live template with shortcut
provider
- Live template with attributes to disable IL2CPP checks with shortcut
il2cpp_nochecks
- Live templates for iterate Filter using Stash
iterate_filter_stash
or withoutiterate_filter
How to import templates to your project:
- Download Gist as a file
- Open your project in Rider
- Open settings and select desired layer(personal/team-shared/etc) in
Manage Layers
window - Use
Import from File...
, select downloaded Gist-file and pressOK
in appeared window - Now you've imported templates, but they're not available in
Add new...
yet - Open layer with imported templates and open Editor -> File Templates -> C# and/or Unity context
- Find templates with
Morpeh
in name and switchAdd to "New..." menu
toggle - ???
- Profit!
You can install it like ScriptTemplates in Morpeh itself. (In Unity inspector: Packages -> Morpeh Helpers -> Packages -> ScriptTemplates.unitypackage).
It contains templates for each Simple update system with various number of components.