当前位置:网站首页>Unity ECS dots notes

Unity ECS dots notes

2022-04-23 20:35:00 One Mr rabbit one

Entity

Component

System

Job

  • C# Although support Thread, But in Unity Only data can be processed in , for example : Internet news 、 download . If you want to Thread Call in Unity Of API That's not going to work .
  • job Using the main thread in API Will report a mistake :“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;
        }

Should be changed to :

        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;
        }

版权声明
本文为[One Mr rabbit one]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210548406273.html