unity-ECS和JobSystem
官方也在预览版支持ecs架构, 看了相关测试性能还是提升的很恐怖的, 充分利用cpu多核的 job system.
之前玩过一下 GitHub 上一下开源的 ecs 架构的工程 : Entitas-CSharp, star 还是比较高的, 之前相关总结: unity-ECS架构Entitas记录
前篇
- 官方资料
- Converting your game to DOTS - Unity at GDC 2019 - https://www.youtube.com/watch?v=QbnVELXf5RQ
- 视频介绍: https://www.youtube.com/watch?v=kwnb9Clh2Is
- 使用 Unity ECS开发《我的世界》
- 《守望先锋》架构设计与网络同步 – GDC2017 精品分享实录 - https://gameinstitute.qq.com/community/detail/114516
- 浅谈《守望先锋》中的 ECS 构架 (云风) - https://blog.codingnow.com/2017/06/overwatch_ecs.html#more
- 不错的系列教程 - https://www.youtube.com/playlist?list=PLzDRvYVwl53s40yP5RQXitbT--IRcHqba
- Getting Started with ECS in Unity 2019 - https://www.youtube.com/watch?v=ILfUuBLfzGI
- Getting Started with the Job System in Unity 2019 - https://www.youtube.com/watch?v=C56bbgtPr_w
- Get Started with the Unity* Entity Component System (ECS), C# Job System, and Burst Compiler, 这里比较直观的解释了 ecs
这个 ecs 开始火起来的应该是 守望先锋 带出来的. 《守望先锋》架构设计与网络同步 – GDC2017 精品分享实录
说明
参考里面的说明: Get Started with the Unity* Entity Component System (ECS), C# Job System, and Burst Compiler
简单的说
ECS: Entity Component System
- Entity: 装 Component 数据的一个容器.
- Component: 只有数据的定义, 没有方法.
- System: 业务逻辑部分. 不同的行为定义成不同的 system, 通过 Component 筛选出感兴趣的 Entity 做逻辑.
这样设计是为了 内存紧凑连续, 减少内存碎片, cpu寻址快.
Job System: 充分利用cpu多个核心, 并行计算.
Burst Compiler: Burst is a compiler, it translates from IL/.NET bytecode to highly optimized native code using LLVM.
当这三个东西结合起来一起用的时候, 性能提升的很恐怖, 在加上 instance 的话就不得了了.
但是现在对ECS可视化编辑还不支持
使用
- 使用 Burst 需要在 package manager 中导入 Burst
- 使用 ecs 需要在 package manager 中导入 Entities
测试仓库: https://github.com/yangxuan0261/ecs_GettingStarted_Jobs
备忘
暂时还没装 2019, 所有 ecs 还没做测试, 这里记一下 ecs 与 job system 结合工作的方式:
其实简单的总结就是在 ecs 中的 system 中做逻辑计算部分, 用 job system 来做.