用途:指导在 Unity 6+ 中实现 DOTS(Entity Component System + Job System + Burst Compiler),覆盖 authoring→baking→system→query→job 完整工作流,面向数千实体的高性能场景。聚焦现代 API:ISystem、SystemAPI.Query、IJobEntity;不推荐已弃用的 Entities.ForEach 与默认使用 SystemBase。
依赖包:com.unity.entities(Unity 6 需 >= 1.3.x)、com.unity.burst(>= 1.8.x)、com.unity.collections(>= 2.4.x);可选 com.unity.entities.graphics、com.unity.physics、com.unity.transforms。需具备基础 MonoBehaviour 知识以理解 authoring→baking 过渡。
快速上手:安装 DOTS 包;创建 authoring MonoBehaviour 与 IComponentData(struct);创建 Baker 完成 authoring→entity 转换;将 GameObject 放入 SubScene(baking 必需);创建带 SystemAPI.Query 的 ISystem;为 system 与 job 添加 [BurstCompile]。
适用判断:原型或小型游戏(<100 动态实体)用 MonoBehaviour 即可;中型(100-1000)优先优化 MonoBehaviour;大规模模拟(1000+ 相似实体,如人群、自定义粒子、体素、RTS)适合 DOTS;仅需 CPU 密集计算(寻路、AI、自定义物理)可只用 Job System + Burst 而不上 ECS;迁移旧项目可用混合方案;全新且实体众多的项目可用完整 DOTS。
规则要点:使用 ISystem(struct)而非 SystemBase(class);为 ISystem 与 job 加 [BurstCompile];用 SystemAPI.Query 而非 Entities.ForEach;用 RefRO/RefRW 访问组件;authoring GameObject 放入 SubScene;Dispose NativeContainer(Allocator.Temp 除外);并行处理优先 IJobEntity;优先 IEnableableComponent。禁止在 IComponentData 中使用托管类型(string、class、List、数组);禁止在 job 中访问主线程(如 Debug.Log);禁止不 Dispose 的 NativeContainer;禁止 Entities.ForEach;不默认使用 SystemBase。
路线图:Unity 6.4 起 com.unity.entities 转为内置 core 包,无需手动安装;Unity 6.5(计划)Entity 类型改为 64 位 ID,可能影响自定义序列化与在 NativeContainer 中存储 Entity,建议避免持久化原始 Entity,改用业务标识。
限制:资料未提供具体性能数据、收费信息或平台支持范围;故障排查与相关技能(/perf-audit、/unity-code-gen、/unity-animation)及参考文档见原资料。