审查这个生成的死亡标记系统。
把生命值不大于零的实体标记为死亡,保留已有 Job 依赖,并让主线程在真正需要结果前保持可用。
csharp
using Unity.Burst;
using Unity.Entities;
[BurstCompile]
public partial struct DeathSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var x = 0f;
foreach (var (health, entity) in
SystemAPI.Query<RefRO<Health>>().WithEntityAccess())
{
if (health.ValueRO.Value <= x)
state.EntityManager.AddComponent<Dead>(entity);
}
new CountLivingJob().ScheduleParallel();
state.Dependency.Complete();
}
}
生成代码仅作示例,不代表任何特定模型