当前位置: 首页 > news >正文

网页设计与网站开发项目柑桔种植服务网站开发

网页设计与网站开发项目,柑桔种植服务网站开发,安徽住房与城乡建设门户网站,凡科网干嘛的最近DOTS发布了正式的版本, 我们来分享一下DOTS里面Baking核心机制#xff0c;方便大家上手学习掌握Unity DOTS开发。今天给大家分享的Baking机制中的Filter Baking Output与Prefab In Baking。 对啦#xff01;这里有个游戏开发交流小组里面聚集了一帮热爱学习游戏的零基础…最近DOTS发布了正式的版本, 我们来分享一下DOTS里面Baking核心机制方便大家上手学习掌握Unity DOTS开发。今天给大家分享的Baking机制中的Filter Baking Output与Prefab In Baking。 对啦这里有个游戏开发交流小组里面聚集了一帮热爱学习游戏的零基础小白也有一些正在从事游戏开发的技术大佬欢迎你来交流学习。 Filter Baking Output 机制 在默认情况下,Baking会为每个GameObject生成的Entity与Component, 这些entity都会被创建到Conversion World里面。然后在创作的时候不是所有的GameObject都需要被转换成Entity。例如: 在一个样条曲线上一个控制点在创作的时候被用到了但是bake成ecs数据后可能就再也没有用了所以不需要把这个控制点Bake成entity。 为了不把这个GameObject Bake产生的Entity输出到World并保存到entity scene里面,我们可以给这个Entity添加一个BakingOnlyEntity tag Component。当你添加了这个tag component后Baking系统就不会把你这个entity存储到entity scene里面也不会把这个entity生成到运行的main World里面。我们可以直接在Baker函数里面添给entity 添加一个BakingOnlyEntity的组件数据,也可以在Authoring GameObject里面添加一个 BakingOnlyEntityAuthoring的组件,这两种方式都可以达到同样的效果没有区别。 你也可以给组件添加注解[BakingType],[TemporaryBakingType] attributes过滤掉掉组件component,让它不输出到entity中。 [TemporaryBakingType]:被这个attributes注记的Component会在Baking Output的时候不会输出到entity。这个Component只会存活在Baker过程中,Baker结束以后就会销毁。 我们有时候需要在Baking System里面批量处理一些组件数据处理完后这些组件就没有用了。例如,baker 把一个bounding box 转换成了ecs component 数据接下来我们定义了一个Baking System批量处理所有的entity,来计算entity的凸包。计算完成后原来的bounding box组件就可以删除了这种情况下就可以使用上面的Filter Component Bake output机制。 Prefab In Baking机制 生成entity prefab到entity scene以后我们就可以像使用普通的Prefab创建GameObject一样来创建entity到世界。但是使用enity prefab之前一定要确保它已经被Baker到了entity scene。当预制体实例化到Authoring Scene中的时候Baking把它当作普通的GameObject来进行转换不会把它当作预制体。 生成一个entity prefab你需要注册一个Baker,在Bake函数里面添加一个依赖关系让这个依赖于Authoring GameObject Prefab。然后Prefab将会被bake出来。我们搞一个组件保存了entity prefab的一个引用那么unity就会把这个entity prefab 序列化到subscene中。当需要使用这个entity prefab的时候就能获取到。代码如下: public struct EntityPrefabComponent : IComponentData{public Entity Value;}public class GetPrefabAuthoring : MonoBehaviour{public GameObject Prefab;}public class GetPrefabBaker : BakerGetPrefabAuthoring{public override void Bake(GetPrefabAuthoring authoring){// Register the Prefab in the Bakervar entityPrefab GetEntity(authoring.Prefab, TransformUsageFlags.Dynamic);// Add the Entity reference to a component for instantiation latervar entity GetEntity(TransformUsageFlags.Dynamic);AddComponent(entity, new EntityPrefabComponent() {Value entityPrefab});}}#endregion 在Baking的时候当我们需要引用一个entity prefab, 可以使用EntityPrefabReference。这个会把它序列化到entity scene文件里面去。运行的时候直接load进来就可以使用了。这样可以防止多个subscene不用重复拷贝生成同一个Prefab。 #region InstantiateLoadedPrefabspublic partial struct InstantiatePrefabReferenceSystem : ISystem{public void OnStartRunning(ref SystemState state){// Add the RequestEntityPrefabLoaded component to the Entities that have an// EntityPrefabReference but not yet have the PrefabLoadResult// (the PrefabLoadResult is added when the prefab is loaded)// Note: it might take a few frames for the prefab to be loadedvar query SystemAPI.QueryBuilder().WithAllEntityPrefabComponent().WithNonePrefabLoadResult().Build();state.EntityManager.AddComponentRequestEntityPrefabLoaded(query);}public void OnUpdate(ref SystemState state){var ecb new EntityCommandBuffer(Allocator.Temp);// For the Entities that have a PrefabLoadResult component (Unity has loaded// the prefabs) get the loaded prefab from PrefabLoadResult and instantiate itforeach (var (prefab, entity) inSystemAPI.QueryRefROPrefabLoadResult().WithEntityAccess()){var instance ecb.Instantiate(prefab.ValueRO.PrefabRoot);// Remove both RequestEntityPrefabLoaded and PrefabLoadResult to prevent// the prefab being loaded and instantiated multiple times, respectivelyecb.RemoveComponentRequestEntityPrefabLoaded(entity);ecb.RemoveComponentPrefabLoadResult(entity);}ecb.Playback(state.EntityManager);ecb.Dispose();}}#endregion 实例化entity prefab可以使用EntityManager与entity command buffer。 #region InstantiateEmbeddedPrefabspublic partial struct InstantiatePrefabSystem : ISystem{public void OnUpdate(ref SystemState state){var ecb new EntityCommandBuffer(Allocator.Temp);// Get all Entities that have the component with the Entity referenceforeach (var prefab inSystemAPI.QueryRefROEntityPrefabComponent()){// Instantiate the prefab Entityvar instance ecb.Instantiate(prefab.ValueRO.Value);// Note: the returned instance is only relevant when used in the ECB// as the entity is not created in the EntityManager until ECB.Playbackecb.AddComponentComponentA(instance);}ecb.Playback(state.EntityManager);ecb.Dispose();}}#endregion 实例化EntityPrefabReference,可以使用如下代码:#region InstantiateLoadedPrefabspublic partial struct InstantiatePrefabReferenceSystem : ISystem{public void OnStartRunning(ref SystemState state){// Add the RequestEntityPrefabLoaded component to the Entities that have an// EntityPrefabReference but not yet have the PrefabLoadResult// (the PrefabLoadResult is added when the prefab is loaded)// Note: it might take a few frames for the prefab to be loadedvar query SystemAPI.QueryBuilder().WithAllEntityPrefabComponent().WithNonePrefabLoadResult().Build();state.EntityManager.AddComponentRequestEntityPrefabLoaded(query);}public void OnUpdate(ref SystemState state){var ecb new EntityCommandBuffer(Allocator.Temp);// For the Entities that have a PrefabLoadResult component (Unity has loaded// the prefabs) get the loaded prefab from PrefabLoadResult and instantiate itforeach (var (prefab, entity) inSystemAPI.QueryRefROPrefabLoadResult().WithEntityAccess()){var instance ecb.Instantiate(prefab.ValueRO.PrefabRoot);// Remove both RequestEntityPrefabLoaded and PrefabLoadResult to prevent// the prefab being loaded and instantiated multiple times, respectivelyecb.RemoveComponentRequestEntityPrefabLoaded(entity);ecb.RemoveComponentPrefabLoadResult(entity);}ecb.Playback(state.EntityManager);ecb.Dispose();}}#endregion 在实例化EntityPrefabReference之前Unity必须要先加载对应的entity prefab,然后才能使用它添加RequestEntityPrefabLoaded组件能确保entity prefab被加载。Unity会PrefabLoadResult加载到带有RequestEntityPrefabLoaded同一个entity上。 预制体也是entity,也可以被查询到如果需要把一个预制体被查询到,可以在查询条件上添加IncludePrefab。 #region PrefabsInQueries// This query will return all baked entities, including the prefab entitiesvar prefabQuery SystemAPI.QueryBuilder().WithAllBakedEntity().WithOptions(EntityQueryOptions.IncludePrefab).Build(); #endregion 使用EntityManager与entity command buffer也可以销毁一个预制体节点,代码如下:#region DestroyPrefabsvar ecb new EntityCommandBuffer(Allocator.Temp);foreach (var (component, entity) inSystemAPI.QueryRefRORotationSpeed().WithEntityAccess()){if (component.ValueRO.RadiansPerSecond 0){ecb.DestroyEntity(entity);}}ecb.Playback(state.EntityManager);ecb.Dispose();#endregion 今天的Baking 系列就分享到这里了关注我学习更多的最新Unity DOTS开发技巧。
http://www.hkea.cn/news/14531560/

相关文章:

  • 全国兼职网站建设免费咨询法律
  • 网站设计师要学什么大连网站设计制作方案
  • 去国外做赌钱网站东莞横沥中学
  • jfinal怎么做网站wordpress点击排行小工具
  • 潍坊高密网站建设wordpress4.7添加菜单
  • 创建网站模板网络营销培训课程
  • 广告联盟网站怎么做网页设计实训报告不足
  • 常熟企业网站建设建设企业网站管理的重要性
  • 汽车最专业的网站建设如何开通公众号
  • 杭州个人做网站网页制作公司的小客户有哪些
  • 南京网站建设 雷仁网防爆玻璃门网站建设
  • 网站工作室和网络公司超凡网络网站
  • 广州营销推广网站网站制作从零开始
  • 企业网站建设规划设计任务书小蜜蜂网站建设
  • 郑州定制网站开发春节期间西安有什么好玩的
  • 一个公司做几个网站制作h5
  • 网站开发哪里便宜wordpress主叶SEO优化
  • 网站建设 上海网站建设qq网页注册入口
  • 建设的网站太卡专门卖电子产品的网站
  • 乐清网站改版公司外贸订单一般在哪个平台接
  • 信息技术九年级上册网站咋做新乡市网站建设电脑培训班
  • 网页给别人做的 网站后续收费吗对电子商务网站建设的理解
  • 网站建设策划书在哪济南兴田德润实惠吗网站美工设计培训学校
  • 网站在线制作软件做礼品贸易好的网站
  • 自己用电脑网站建设河北三河建设局网站
  • 做网站头视频网站维护需要什么
  • 安卓系统优化大师seo顾问什么职位
  • 有没有转门做乐器演奏的网站成都网站建设服务功能
  • 最大的房产网站排名wordpress手机边栏
  • 免费网站设计网站媒体给房开做内容推广