Skip to content

Commit 9d41040

Browse files
committed
initial
1 parent aede996 commit 9d41040

18 files changed

+1011
-1
lines changed

.editorconfig

Lines changed: 708 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 CodeWriter Packages
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LICENSE.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
# Morpeh.SystemStateProcessor
1+
# Morpeh.SystemStateProcessor [![Github license](https://img.shields.io/github/license/codewriter-packages/Morpeh.SystemStateProcessor.svg?style=flat-square)](#) [![Unity 2021.3](https://img.shields.io/badge/Unity-2021.3+-2296F3.svg?style=flat-square)](#) ![GitHub package.json version](https://img.shields.io/github/package-json/v/codewriter-packages/Morpeh.SystemStateProcessor?style=flat-square)
2+
_Reactivity for Morpeh ECS_
3+
4+
## How to use?
5+
6+
```csharp
7+
using System;
8+
using Scellecs.Morpeh;
9+
using Scellecs.Morpeh.Systems;
10+
using UnityEngine;
11+
12+
[Serializable] public struct HeroComponent : IComponent { }
13+
[Serializable] public struct HeroDamagedMarker : IComponent { }
14+
[Serializable] public struct HeroDeadMarker : IComponent { }
15+
16+
public class HealthBarSystem : UpdateSystem {
17+
[SerializeField] private GameObject healthBarPrefab;
18+
19+
private SystemStateProcessor<HealthBarSystemStateComponent> heroProcessor;
20+
21+
public override void OnAwake() {
22+
heroProcessor = World.Filter.With<HeroComponent>().With<HeroDamagedMarker>().Without<HeroDeadMarker>()
23+
.ToSystemStateProcessor(CreateHealthBarForHero, RemoveHealthBarForHero);
24+
}
25+
26+
public override void OnUpdate(float deltaTime) {
27+
heroProcessor.Process();
28+
}
29+
30+
// Called when an entity has been added to the Filter
31+
private HealthBarSystemStateComponent CreateHealthBarForHero(Entity heroEntity) {
32+
var healthBar = Instantiate(healthBarPrefab);
33+
34+
return new HealthBarSystemStateComponent {
35+
healthBar = healthBar,
36+
};
37+
}
38+
39+
// Called when an entity has been removed from filter or has been destroyed
40+
private void RemoveHealthBarForHero(ref HealthBarSystemStateComponent state) {
41+
Destroy(state.healthBar);
42+
}
43+
44+
[Serializable]
45+
private struct HealthBarSystemStateComponent : ISystemStateComponent {
46+
public GameObject healthBar;
47+
}
48+
}
49+
50+
public class DestroySystem : UpdateSystem {
51+
private Filter _toDestroyFilter;
52+
53+
public override void OnAwake() { }
54+
55+
public override void OnUpdate(float deltaTime) {
56+
foreach (var entity in _toDestroyFilter) {
57+
// MigrateSystemStateComponents must be called before each RemoveEntity
58+
World.MigrateSystemStateComponents(entity);
59+
World.RemoveEntity(entity);
60+
}
61+
}
62+
}
63+
```
64+
65+
## License
66+
67+
Morpeh.SystemStateProcessor is [MIT licensed](./LICENSE.md).

README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Scellecs.Morpeh.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Scellecs.Morpeh
2+
{
3+
public interface ISystemStateComponent : IComponent
4+
{
5+
}
6+
}

Scellecs.Morpeh/ISystemStateComponent.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"reference": "Scellecs.Morpeh"
3+
}

Scellecs.Morpeh/Scellecs.Morpeh.asmref.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)