-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestroyEntitySystem.cs
More file actions
33 lines (28 loc) · 1.07 KB
/
DestroyEntitySystem.cs
File metadata and controls
33 lines (28 loc) · 1.07 KB
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
using Unity.Entities;
namespace Dev100.ECS
{
public struct DestroyEntityTag : IComponentData {}
[UpdateInGroup(typeof(SimulationSystemGroup), OrderLast = true)]
public partial struct DestroyEntitySystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<BonusLevelPoints>();
}
public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(state.WorldUpdateAllocator);
var bonusLevelPoints = SystemAPI.GetSingletonRW<BonusLevelPoints>();
foreach (var (_, entity) in SystemAPI.Query<DestroyEntityTag>().WithEntityAccess())
{
if (SystemAPI.HasComponent<AddPointTag>(entity))
{
bonusLevelPoints.ValueRW.Value++;
BonusLevelManager.Instance.UpdateGnomesDestroyedUI(bonusLevelPoints.ValueRO.Value);
}
ecb.DestroyEntity(entity);
}
ecb.Playback(state.EntityManager);
}
}
}