Unity DOTS 1.0 (5) Baking System、Baking phases 和 Baking World

server/2024/10/19 7:33:37/

Baking System

  • 一个 baking system在处理数据的方式上不同于baker。和baker一个一个处理components不同,它是进行批处理的,并且它可以经由job 和burst 大幅提升处理性能。
  • baking system是在entity创建完成后运行,所以它可以访问到所有初始创建的Entity,包括baker创建的。
  • baking system可以随意改变world,包括创建新的entity。但是在system中创建的entity,不会在场景Bake结束以后销毁;也就是在这个阶段创建的Entity是可以留在我们的世界里面的。
    你也可以来创建entity在多个Baking System之间进行数据传递,如果你希望这个entity在你这个bake场景结束以后有销毁你创建的entity,那么你创建entity就必须要在Baker里面创建,在Baker里面创建的entity(使用CreateAdditionalEntity方法来创建),就会在Baker结束以后销毁

创建一个Baking System

  • 给System做一个特定注解:[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)] attribute.有了这个注解,Baking 系统就会识别这个System,把它当作Baking System加入到的Baking World里面。

示例代码:给出了代码实现,给所有的有带有组件A的entity加一个tag component,如果一个entity没有组件A,但是又带了tag component,我们就把这个tag component从entity里面删除掉;

public struct AnotherTag : IComponentData { }[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]partial struct AddTagToRotationBakingSystem : ISystem{public void OnUpdate(ref SystemState state){//查找出所有拥有RotationSpeed Component并且没有AnotherTagComponent的Entityvar queryMissingTag = SystemAPI.QueryBuilder().WithAll<RotationSpeed>().WithNone<AnotherTag>().Build();//然后批量添加AnotherTagstate.EntityManager.AddComponent<AnotherTag>(queryMissingTag);// Omitting the second part of this function would lead to inconsistent// results during live baking. Added tags would remain on the entity even// after removing the RotationSpeed component.var queryCleanupTag = SystemAPI.QueryBuilder().WithAll<AnotherTag>().WithNone<RotationSpeed>().Build();//然后批量删除AnotherTagstate.EntityManager.RemoveComponent<AnotherTag>(queryCleanupTag);}}

这个代码就实现了批量处理Entity。

Baking phases (阶段)

0. 执行PreBakingSystemGroup 分组内容

1. Entity 创建:

  • Unity会先创建出来场景里面的每个GameObject对应的entity, entity只是一个空的容器(internal metadata),没有ComponentData;

2. Baker phase:

  • 对Authoring GameObject做单个单个的转换,转换成ecs entity + component;执行我们每个数据的Bakers,来完成转换;同一种类型的Component转换的时候,使用同一种baker;EntityA, EntityB,但是都有Authoring Component使用同一个Baker;
  • Unity提供的组件数据都是使用系统自带默认的Baker来进行转换;
  • Unity执行Bakers的顺序是不固定的,所以Baker之间的相互依赖是不被允许的。不能在baker A Entity的时候去读取或更改B Entity的Component
  • 只能进行添加组件操作

3. Baking System phase:

  • 所有Baker执行完了后,进入Baking System阶段
  • 对所有的entity 与component来做批量的数据处理,提升性能。
  • 所有的Baking System只能在Baking过程中运行;可以通过注解[UpdateAfter, UpdateBefore, and UpdatelnGroup ]来标记执行顺序;
  • Unity 已经提供了一些默认的分组,按照这样的特定顺序;
    • PreBakingSystemGroup:在Baker之前来调用它分组下面的所有的system(这个组在Baker之前,是个例外);
    • TransformBakingSystemGroup:就在Baker之后,这个分组,可以用来做一些特定的数据转换。
    • BakingSystemGroup: 用户一般编写的所有的Baking System都会被放入到这个分组下。
    • PostBakingSystemGroup:你可以编写Baking System来做结束时候的一些处理。

Baking World

  • 我们每个Authroing Scene在Bake的时候都是独立分来来处理的;
  • 后台每次一个一个场景的来进行Bake处理;
  • 每个subscene,都会有2个World: Conversion world, Shadow worldConversion world。所有的Baker 与Baking System都是运行在它里面。
  • Shadow world:保存了上一次Baking的处理结果,可以通过比较看本次修改了哪些地方;
  • baking完成后,比较两次世界的变化,然后同步到main word(用户可见world)

http://www.ppmy.cn/server/15939.html

相关文章

阿斯达年代记三强争下载教程 阿斯达年代记游戏下载教程

《阿斯达年代记三强争霸》作为一款蔚为壮观的MMORPG巨制&#xff0c;是由Netmarble与STUDIO DRAGON携手推出的扛鼎之作&#xff0c;预计于4月24日迎来万众瞩目的公开测试。游戏的中心舞台聚焦于阿斯达大陆的统治权争夺&#xff0c;通过三大阵营——阿斯达联邦、亚高同盟与边缘叛…

【注解】Mapper的注解 @Mapper、@Repository、@MapperScan

Mapper的注解 Mapper、Repository、MapperScan 一、Mapper1.1、主要作用1.2、示例 二、Repository2.1、主要作用2.2、示例2.3、注意事项 三、MapperScan Mapper 是 Mybatis 的注解&#xff0c;和 Spring 没有关系&#xff0c; Repository 是 Spring 的注解&#xff0c;用于声明…

RattbitMQ安装

1.RabbitMQ是什么? RabbitMQ是消息队列的一种&#xff0c;生态好&#xff0c;好学习&#xff0c;易于理解&#xff0c;时效性强,支持很多不同语言的客户端,扩展性、可用性都很不错。学习性价比非常高的消息队列&#xff0c;适用于绝大多数中小规模分布式系统。 今天先来简单讲…

Java在区块链开发中的作用及发展

Java在区块链开发中的作用以及发展 一、引言 随着信息技术的飞速发展&#xff0c;区块链技术作为一种新兴的去中心化分布式账本技术&#xff0c;正逐渐引起人们的广泛关注。区块链以其独特的不可篡改、去中心化、安全可信等特性&#xff0c;在数字货币、供应链管理、金融科技…

springSecurity简单直接说明

引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombo…

浏览器JavaScript兼容解决方案整理

1、addEventListener 与 attachEvent 区别 attachEvent ——兼容&#xff1a;IE7、IE8&#xff1b;不兼容firefox、chrome、IE9、IE10、IE11、safari、opera。 addEventListener——兼容&#xff1a;firefox、chrome、IE、safari、opera&#xff1b;不兼容IE7、IE8 解决方案&…

2024系统架构师---论软件系统架构风格

论软件系统架构风格 系统架构风格(System Architecture Style)是描述某一特定应用领域中系统组织方式的惯用模式架构风格定义了一个词汇表和一组约束&#xff0c;词汇表中包含一些构件和连接件类型&#xff0c;而这组约束指出系统是如何将这些构件和连接件组合起来的口软件系统…

Java | Leetcode Java题解之第44题通配符匹配

题目&#xff1a; 题解&#xff1a; class Solution {public boolean isMatch(String s, String p) {int sRight s.length(), pRight p.length();while (sRight > 0 && pRight > 0 && p.charAt(pRight - 1) ! *) {if (charMatch(s.charAt(sRight - 1)…