审查生成的死亡系统

来自 Unity DOTS
Unity 6.6 / Entities 1.4.8 / Burst 1.8.30 高级 6分钟 找出 4处问题

审查这个生成的死亡标记系统。

把生命值不大于零的实体标记为死亡,保留已有 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();
    }
}

生成代码仅作示例,不代表任何特定模型

在试验场中打开
报告错误