Unity Entities 中的 AlwaysSynchronizeSystemAttribute 特性

https://docs.unity3d.com/Packages/[email protected]/api/Unity.Entities.AlwaysSynchronizeSystemAttribute.html

官方文档解释

看不懂说人话就是每次JobComponentSystem执行的时候都要等待他自己所依赖的执行完成才行执行自己。同步频率每一帧。

所以以下俩份代码等价:

[AlwaysSynchronizeSystem]
public class PlayerInputSystem : JobComponentSystem
{
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        Entities.ForEach() =>
        {
           
        }).Run();
        return inputDeps;
    }
}
public class PlayerInputSystem : JobComponentSystem
{
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        inputDeps.Complete();
        Entities.ForEach((ref PaddleMovementData moveData, in PaddleInputData inputData) =>
        {
            moveData.direction = 0;
            moveData.direction += Input.GetKey(inputData.upKey) ? 1 : 0;
            moveData.direction -= Input.GetKey(inputData.downKey) ? 1 : 0;
        }).Run();
        return new JobHandle();
    }
}

 

你可能感兴趣的:(Unity3D,DOTS)