8

因为 Unity ECS,我最近阅读了很多关于 ECS 的内容。

ECS 架构有很多明显的优势:

ECS是面向数据的:数据倾向于线性存储,这是系统访问它的最佳方式。在体面的 ECS 实现中,数据是按顺序存储和处理的,对于任何给定的系统处理它的组件集几乎没有中断或没有中断。

ECS 是非常分区的:它自然地将数据与行为分开,强制“组合而不是继承”(google it)等。

ECS 对并行处理和多线程非常友好:由于事物的结构化方式,许多实体和组件可以避免冲突并与其他系统并行处理。


然而,ECS 的缺点(与 OOP 或实体组件 [无系统] 相比,直到最近在包括 Unity 在内的游戏引擎中很常见)很少被谈论,如果有的话。它们存在吗?如果他们这样做,他们是什么?

4

2 回答 2

9

以下是我从研究中收集到的几点:

  • 系统非常依赖于它们的顺序。在现有系统之间引入新系统可能是一个挑战。

  • 您还需要尽可能提前计划您的数据,因为它们可能会被许多系统使用。更改组件的内容可能会破坏相当多的系统。

  • 尽管调试系统的流程很容易,但调试单个组件的更改也比较困难,并且无法全面了解实体在其所有组件中发生的情况。我不确定 Unity 是否为此引入了新的调试功能。

  • 如果您计划在您的团队中使用 ECS,那么向不熟悉它的开发人员介绍一种新的范例可能是一个挑战。入职时间可能更长,开销更大。

希望这能给你一个好的起点。

于 2019-12-23T00:55:49.217 回答
2

When it comes to Unity3D, one disadvantage which comes to my mind is that the ECS there is quite restricted to the Unity classes (e.g. MonoBehaviour) and lifecycle. That means that the components are not easy to share with other C# code whereas a well-designed OOP class is reusable by other platforms than Unity.

Another point which comes to my mind is that using Interfaces with Components is sometimes not easy in Unity because only in the newest version serialization of interfaces are supported. Without serialization there don't appear inside of the inspector.

于 2019-10-29T10:19:21.357 回答