ECS 简略版说明五:Baking and entity scenes

目录

 

Baking and entity scenes

Creating and editing sub scenes

Accessing data in a baker

Loading and unloading entity scenes


Baking and entity scenes

Baking 是一个把 sub scenes 转变成 entity scenes 的过程,使用 bakers和 baking systems:

  • sub scene is a Unity scene asset that's embedded in another scene by the SubScene MonoBehaviour.
  • An entity scene is a serialized set of entities and components that can be loaded at runtime.
  • baker is a class extending Baker<T>, where T is a MonoBehaviour. A MonoBehaviour with a Baker is called an authoring component.
  • baking system is a normal system marked with the [WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)] attribute. (Baking systems are fully optional and generally only required for advanced use cases.)

Baking a sub scene is done in a few main steps:

  1. Sub scene的每一个GameObject,创建对应的实体
  2. The baker of each authoring component in the sub scene is executed. Each baker can read the authoring component and add components to the corresponding entity.
  3. 执行baking systems. Each system can read and modify the baked entities in any way: set components, add components, remove components, create additional entities, or destroy entities. 

 当sub-scene更改时,就会重新baked:

  1. 只有 读取更改的 authoring components 的bakers,才会re-executed.
  2. baking systems 会 re-executed 
  3. The live entities in Edit mode or Play mode are updated to match the results of baking. (This is possible because baking tracks the correspondence of baked entities to live entities.)

Creating and editing sub scenes

勾选框表示是否可以编辑,勾选上打开该场景时,就会加载对应的资源,如果不在该场景后,可以取消勾选,降低消耗

Accessing data in a baker

baker的 authoring component可以自动获取,但是其它的数据,需要添加到dependencies 中才可以访问:

Baker methodDescription
GetComponent<T>()Accesses any component of any GameObject in the Sub Scene.
DependsOn()Tracks an asset for this Baker.
GetEntity()Returns the id of an entity baked in the sub scene or baked from a prefab. (The entity will not yet have been fully baked, so you should not attempt to read or modify the components of the entity.)

Loading and unloading entity scenes

为了流加载,场景被分为多个sections ,通过index 识别. 每一个section属于哪一个 entity 根据 SceneSection shared component 组件决定, By default, an entity belongs to section 0, but this can be changed by setting SceneSection during baking.

⚠ IMPORTANT
在bake过程中,子场景中的实体只能引用同一section或section 0的其他实体( section 0 总是在其他section之前加载 and 只有当场景本身被卸载时才会被卸载).

当一个场景被加载时,它由一个metadata的实体来表示,它的每个部分也都由一个实体来表示. 单个section通过操作 entity's RequestSceneLoaded component 来实现load、unload, 当该组件发生变化时,SceneSectionStreamingSystem in the SceneSystemGroup 会收到回调。

The SceneSystem 提供了 loading and unloading entity scenes 的静态方法,不是section scene哦:

SceneSystem methodDescription
LoadSceneAsync()Initiates loading of a scene. Returns an entity that represents the loaded scene.
LoadPrefabAsync()Initiates loading of a prefab. Returns an entity that references the loaded prefab.
UnloadScene()Destroys all entities of a loaded scene.
IsSceneLoaded()Returns true if a scene is loaded.
IsSectionLoaded()Returns true if a section is loaded.
GetSceneGUID()Returns the GUID representing a scene asset (specified by its file path).
GetScenePath()Returns the path of a scene asset (specified by its GUID).
GetSceneEntity()Returns the entity representing a scene (specified by its GUID).
⚠ IMPORTANT
Entity scene and section加载总是 asynchronous,并且不能保证在请求之后需要多长时间才能加载数据.在大多数情况下,代码应该检查从场景加载的特定数据是否存在,而不是检查场景本身的加载状态 这种方法避免了将代码绑定到特定场景。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
The following is the data that you can add to your input file (as an example). Notice that the first line is going to be a line representing your own hobbies. In my case, it is the Vitaly,table tennis,chess,hacking line. Your goal is to create a class called Student. Every Student will contain a name (String) and an ArrayList<String> storing hobbies. Then, you will add all those students from the file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here is an example file containing students (the first line will always represent yourself). NOTE: eventually, we will have a different file containing all our real names and hobbies so that we could find out with how many people each of us share the same hobby. Vitaly,table tennis,chess,hacking Sean,cooking,guitar,rainbow six Nolan,gym,piano,reading,video games Jack,cooking,swimming,music Ray,piano,video games,volleyball Emily,crochet,drawing,gardening,tuba,violin Hudson,anime,video games,trumpet Matt,piano,Reading,video games,traveling Alex,swimming,video games,saxophone Roman,piano,dancing,art Teddy,chess,lifting,swimming Sarah,baking,reading,singing,theatre Maya,violin,knitting,reading,billiards Amy,art,gaming,guitar,table tennis Daniel,video games,tennis,soccer,biking,trumpet Derek,cooking,flute,gaming,swimming,table tennis Daisey,video games,guitar,cleaning,drawing,animated shows,reading,shopping Lily,flute,ocarina,video games,baking Stella,roller skating,sudoku,watching baseball,harp Sophie,viola,ukulele,piano,video games Step 2. Sort the student list in the ascending order of student names and print them all on the screen After reading the file and storing the data in an ArrayList<Student>, your program should sort the ArrayList<Student> in alphabetical order based on their names and then print the students' data (please see an example below). As you can see, here is the list of all students printed in alphabetical order based on their names and hobbies. You are not going to have yourself printed in this list (as you can see, this list does not have Vitaly). Alex: [swimming, video games, saxophone] Amy: [art, gaming, guitar] Daisey: [video games, guitar, cleaning, drawing, animated shows, reading, shopping] Daniel: [video games, tennis, soccer, biking, trumpet] Derek: [cooking, flute, gaming, swimming] Emily: [crochet, drawing, gardening, tuba, violin] Hudson: [anime, video games, trumpet] Jack: [cooking, swimming, music] Lily: [flute, ocarina, video games, baking] Matt: [piano, Reading, video games, traveling] Maya: [violin, knitting, reading, billiards] Nolan: [gym, piano, reading, video games] Ray: [piano, video games, volleyball] Roman: [piano, dancing, art] Sarah: [baking, reading, singing, theatre] Sean: [cooking, guitar, rainbow six] Sophie: [viola, ukulele, piano, video games] Stella: [roller skating, sudoku, watching baseball, harp] Teddy: [chess, lifting, swimming] Step 3. Find all students who share the same hobby with you and print them all on the screen Finally, your program should print the information related to the students who share the same hobby as you. In my case, it would be the following based on the above-mentioned file. There are 0 students sharing the same hobby called "hacking" with me. There are 1 students (Teddy) sharing the same hobby called "chess" with me. There are 2 students (Amy, Derek) sharing the same hobby called "table tennis" with me.
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TO_ZRG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值