This is source generation library for Morpeh Framework. It can replace a lot of boilerplate code in your project.
- Inport
Morpeh.SourceGeneration.dllto your unity project - Disable all ckeckboxes in
Morpeh.SourceGeneration.dllimport settings panel. PressApply - Add
RoslynAnalyzertag toMorpeh.SourceGeneration.dll
If you using assembly definitions you have to plase
Morpeh.SourceGeneration.dllinto folder with.asmdefthat have refference toMorpeh
public partial class FeatureRunner : IFeatureRunner
{
private readonly SomeFeature _someFeature;
}public partial class SomeFeature : IFeature
{
private readonly SomeSystem1 _someSystem1;
private readonly SomeSystem2 _someSystem2;
}Register attribute can be added to a system field in a feature. This system will be registered in the DI container and can be injected into other systems.
public partial class SomeFeature : IFeature
{
[Register] private readonly SomeServiceSystem _someServiceSystem;
}public partial class SomeSystem1 : IInitializeSystem
{
public void Start()
{
// ...
}
}public partial class SomeSystem2 : IUpdateSystem
{
public void Update()
{
// ...
}
}You dont need to initialize stashash it will be initialized and disposed automatically.
public partial class SomeSystem : IStartSystem
{
private Stash<InputMoveDirection> _inputStash;
private Stash<PlayerPosition> _playerPosition;
// ...
}There are extensions for Stashes generated for each component. For marker components without fields, there is the SetOrRemove(Entity entity, bool setOrRemove) extension.
// Some examples
struct SomeComponent : IComponent {}
Stash<SomeComponent> _someStash;
var toggle = /*...*/;
_someStash.SetOrRemove(entity, toggle);For components with fields, there is the new Set(Entity entity, /.../) extension. This allows you to assign values directly without creating a new structure.
// Some examples
struct SomeComponent : IComponent
{
public int Value;
}
Stash<SomeComponent> _someStash;
_someStash.Set(entity, value: 10);You can use generic filters. The first type or tuple defines with components, and an optional second type or tuple defines without components.
public partial class SomeSystem : IStartSystem
{
private Filter<Player> _anyPlayerFilter;
private Filter<Player, Disabled> _activePlayerFilter;
private Filter<(Player, Transform), Disabled> _playerWithTransformFilter;
private Filter<(Player, Transform), (Dead, Disabled)> _alivePlayerFilter;
// ...
}