-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurationSystem.cs
34 lines (32 loc) · 1.22 KB
/
ConfigurationSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Leopotam.EcsLite;
namespace Gemserk.Leopotam.Ecs
{
public class ConfigurationSystem : BaseSystem, IEntityCreatedHandler, IEcsRunSystem
{
public void OnEntityCreated(World world, Entity entity)
{
if (world.HasComponent<ConfigurationComponent>(entity))
{
ref var configuration = ref world.GetComponent<ConfigurationComponent>(entity);
configuration.configuration?.Configure(world, entity);
configuration.configuredVersion++;
}
}
public void Run(EcsSystems systems)
{
var configurations = world.GetComponents<ConfigurationComponent>();
foreach (var entity in world.GetFilter<ConfigurationComponent>()
.Exc<DisabledComponent>()
.End())
{
ref var configuration = ref configurations.Get(entity);
if (configuration.reconfigure)
{
configuration.configuration?.Configure(world, this.GetEntity(entity));
configuration.reconfigure = false;
configuration.configuredVersion++;
}
}
}
}
}