Unity ECS基础构成

1. Entity

与Mono的Gameobject相似,是任何数据挂载的媒介。Entity持有多个Component,通过上面的数据在ComponentSystem中进行运算。

从预制体到Entity的转化与创建
代码创建Entity

2. Component

与Mono的Component相似,但是只持有数据,不会进行任何运算。根据Attribute,可实现类不同功能。

public struct RotationSpeed_ForEach : IComponentData
{
    public float RadiansPerSecond;
}

GenerateAuthoringComponentAttribute : 使IComponentData挂载于GameObject上:

[GenerateAuthoringComponent]

在这里插入图片描述

3. ComponentSystem

ECS原生的运算类,与Entity相互独立,不需要挂载便自动运行(跨场景依旧可运行)。在各个方法中获取Entity上Component的数据,并对其进行运算和修改。
ComponentSystem的写法

DisableAutoCreationAttribute: 使ComponentSystem不会自动生成并运行。

[DisableAutoCreation]

UpdateAfterAttribute:定义ComponentSystem的Update执行顺序,有助于理清逻辑

[UpdateAfter(typeof(SpriteSheetAnimation_Animate))]

4. World

大量System的集合,ECS系统中自带一个默认的DefaultGameObjectInjectionWorld,部分系统功能相关的System都在其中,如SceneSystem,TransformSystem等等。同时也可以创建自定义的World。不同的World之间相互独立。

var defaultWorld=World.DefaultGameObjectInjectionWorld;
var newWorld = new World("World Name");
//查找,筛选
foreach(var tempWorld in World.All)
{
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值