unity-ECS-DOTS笔记

Entity

Component

System

Job

  • C#虽然支持Thread,但是在Unity中只能处理数据,例如:网络消息、下载。如果想在Thread中调用Unity的API那是不行的。
  • job中使用主线程API会报错:“UnityException: GetKeyInt can only be called from the main thread.”
		protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
    
    
            Entities.ForEach((ref Move_Component moveComponent, in Input_Component inputComponent) =>
            {
    
    
                moveComponent.direction = 0;
                moveComponent.direction += Input.GetKey(inputComponent.upKey) ? 1 : 0;
                moveComponent.direction -= Input.GetKey(inputComponent.downKey) ? 1 : 0;
            }).Schedule(inputDeps);
            return default;
        }

应改为:

        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
    
    
            Entities.ForEach((ref Move_Component moveComponent, in Input_Component inputComponent) =>
            {
    
    
                moveComponent.direction = 0;
                moveComponent.direction += Input.GetKey(inputComponent.upKey) ? 1 : 0;
                moveComponent.direction -= Input.GetKey(inputComponent.downKey) ? 1 : 0;
            }).Run();
            return default;
        }

猜你喜欢

转载自blog.csdn.net/weixin_44054505/article/details/118671866