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

wordpress捐北京关键词优化平台

wordpress捐,北京关键词优化平台,做微信小程序网站,一个大型的网站建设最近DOTS发布了正式的版本, 我们来分享一下DOTS里面Aspect机制,方便大家上手学习掌握Unity DOTS开发。 Aspect 机制概述 当我们使用ECS开发的时候,编写某个功能可能需要某个entity的一些组件,如果我们一个个组件的查询出来,可能…

最近DOTS发布了正式的版本, 我们来分享一下DOTS里面Aspect机制,方便大家上手学习掌握Unity DOTS开发。

Aspect 机制概述

当我们使用ECS开发的时候,编写某个功能可能需要某个entity的一些组件,如果我们一个个组件的查询出来,可能参数会写很长。如果我们编写某个功能的时候,需要entity的一些组件的引用,我们如何高效的来获得呢?Unity DOTS引入了Aspect机制。

对惹,这里有一个游戏开发交流小组,大家可以点击进来一起交流一下开发经验呀!

Aspect是一个特殊的数据结构,可以把它理解为是entity中一些组件的引用Wrapper”包装盒”,把entity中的一些组件的引用包含在一起。方便在System中通过这个Aspect来获取entity当中的组件的引用,高效方便的访问entity中的一些组件数据。定义一个Aspect, 需要继承自Iaspect Interface, Aspect里面的成员可以包含以下的内容:

  • Entity类型的引用;
  • RefRW<T> 与RefRO<T>组件数据的引用;
  • EnabledRefRW与EnabledRefRO的Enable Component组件数据的引用;
  • DynamicBuffer<T> 类型数据buffer;
  • shared component 类型的组件的引用;
  • 其它的Aspect类型;

Aspect定义与使用

定义一个Aspect,需要定义一个readonly的partial结构体并继承自接口类IAspect。

using Unity.Entities; 
readonly partial struct MyAspect : IAspect 
{ // Your Aspect code 
}

结构体里面的字段可以使用上面字段所规定的类型, 我们还可以把某个字段通过attribute设置为[Optional]。这样这个字段在entity里面就不是必须的,如果某个entity类没有这个可选字段,也能生成对应的Aspect。如果想要DynamicBuffer字段为只读,可以定义attibute [ReadOnly]。RefRO修饰的组件是只读的,RefRW修饰的组件可读写。

在System中我们要基于定义好的Aspect类型来操作entity中的组件数据,我们可以为Entity生成一个Aspect对象。通过API:SystemAPI.GetAspect<TASpect>来获取entity对应的Aspect对象。

// Throws if the entity is missing any of // the required components of MyAspect. MyAspect asp = SystemAPI.GetAspect<MyAspect>(myEntity);

如果这个entity类型无法生成对应的Aspect,那么asp就会返回null。当我们在System中需要迭代所有Entity的某种Aspect,可以使用API:

SystemAPI.Query

参考代码如下:

struct CannonBall : IComponentData
{public float3 Speed;
}// Aspects must be declared as a readonly partial struct
readonly partial struct CannonBallAspect : IAspect
{// An Entity field in an Aspect gives access to the Entity itself.// This is required for registering commands in an EntityCommandBuffer for example.public readonly Entity Self;// Aspects can contain other aspects.// A RefRW field provides read write access to a component. If the aspect is taken as an "in"// parameter, the field behaves as if it was a RefRO and throws exceptions on write attempts.readonly RefRW<LocalTransform> Transform;readonly RefRW<CannonBall> CannonBall;// Properties like this aren't mandatory. The Transform field can be public instead.// But they improve readability by avoiding chains of "aspect.aspect.aspect.component.value.value".public float3 Position{get => Transform.ValueRO.Position;set => Transform.ValueRW.Position = value;}public float3 Speed{get => CannonBall.ValueRO.Speed;set => CannonBall.ValueRW.Speed = value;}
}
public partial struct MySystem : ISystem
{public void OnUpdate(ref SystemState state){foreach (var cannonball in SystemAPI.Query<CannonBallAspect>()){// use cannonball aspect here}}
}

上面代码中定义了一个struct CannonBall 的ComponentData, 定义了一个CannonBallAspect,包含了entity本身引用,以及所需要的其它组件的引用(字段里面还可以基于get/set)。System中通过查询当前World里面所有含有CannonBallAspect对象的entity,然后统一处理它们。

Aspect的代码自动生成

不同类型的Entity可能有同一个类型的Aspect,那么Unity DOTS如何来处理呢?例如Entity类型A与Entity类型B,都有Aspect所定义的组件与引用,那么系统如何把A类型的Entity与B类型的Entity都生成它对应的Aspcet对象呢?那么这个时候就需要通过扫描所有的代码,来自动生成相关的代码自动生成对应的伪代码如下:

MyAspect CreateAspectWithEntityA(entity实例) { Var myAspect = new MyAspect();把A类entity实例对应的ArchType的ComponentData块的引用,生成一个MyAspect实例。Return myAspect;
}
MyAspect CreateAspectWithEntityB(entity实例) { Var myAspect = new MyAspect();把B类entity实例对应的ArchType的ComponentData块的引用,生成一个MyAspect实例。Return myAspect;
}

entity是否具有某种Aspcet类型的Aspect,也会被快速的生成出来,这样再查询的时候都可以提升查询的速度。具体可以参考相关源码。


文章转载自:
http://dinncofearlessly.ydfr.cn
http://dinncoshaken.ydfr.cn
http://dinncodrivability.ydfr.cn
http://dinncocopulative.ydfr.cn
http://dinncofoxiness.ydfr.cn
http://dinncotympanum.ydfr.cn
http://dinncoearwax.ydfr.cn
http://dinncoreflective.ydfr.cn
http://dinncovettura.ydfr.cn
http://dinncodistributee.ydfr.cn
http://dinncogradual.ydfr.cn
http://dinncoeyeball.ydfr.cn
http://dinncogalliardise.ydfr.cn
http://dinncomariana.ydfr.cn
http://dinncocataplasia.ydfr.cn
http://dinncooptimal.ydfr.cn
http://dinnconiue.ydfr.cn
http://dinncononce.ydfr.cn
http://dinncokhat.ydfr.cn
http://dinnconeedlewoman.ydfr.cn
http://dinncobridle.ydfr.cn
http://dinncovulcanian.ydfr.cn
http://dinncoantiquary.ydfr.cn
http://dinncopirarucu.ydfr.cn
http://dinncodirtiness.ydfr.cn
http://dinncoaustronesian.ydfr.cn
http://dinncobinocle.ydfr.cn
http://dinncohalt.ydfr.cn
http://dinncobreeching.ydfr.cn
http://dinncotheodicean.ydfr.cn
http://dinncochristening.ydfr.cn
http://dinncocockneydom.ydfr.cn
http://dinncocombing.ydfr.cn
http://dinncoslank.ydfr.cn
http://dinncooxytocic.ydfr.cn
http://dinncoruddered.ydfr.cn
http://dinncosupportative.ydfr.cn
http://dinncofranquista.ydfr.cn
http://dinncoramshorn.ydfr.cn
http://dinncomusicology.ydfr.cn
http://dinncoheriot.ydfr.cn
http://dinnconephrostome.ydfr.cn
http://dinncoironhanded.ydfr.cn
http://dinncosweatshop.ydfr.cn
http://dinncoshelterbelt.ydfr.cn
http://dinncocareworn.ydfr.cn
http://dinncobmw.ydfr.cn
http://dinncousar.ydfr.cn
http://dinncotrustworthiness.ydfr.cn
http://dinncoacropathy.ydfr.cn
http://dinncouninsured.ydfr.cn
http://dinncoidentical.ydfr.cn
http://dinncourologist.ydfr.cn
http://dinncodisharmonic.ydfr.cn
http://dinncomacroinvertebrate.ydfr.cn
http://dinncotorun.ydfr.cn
http://dinnconeuroethology.ydfr.cn
http://dinncosecretaire.ydfr.cn
http://dinncoroost.ydfr.cn
http://dinncofructosan.ydfr.cn
http://dinncobiostrategy.ydfr.cn
http://dinncoelectrophoretogram.ydfr.cn
http://dinncogamut.ydfr.cn
http://dinncosylvan.ydfr.cn
http://dinncocosmogenesis.ydfr.cn
http://dinncogodfrey.ydfr.cn
http://dinncoburyat.ydfr.cn
http://dinncophotokinesis.ydfr.cn
http://dinncoantidepressive.ydfr.cn
http://dinncojell.ydfr.cn
http://dinncodizygous.ydfr.cn
http://dinncocorticate.ydfr.cn
http://dinncobabyless.ydfr.cn
http://dinncoquean.ydfr.cn
http://dinncoobsidionary.ydfr.cn
http://dinncozootheism.ydfr.cn
http://dinncosideward.ydfr.cn
http://dinncowootz.ydfr.cn
http://dinncoextermination.ydfr.cn
http://dinncohemophilia.ydfr.cn
http://dinncodemirep.ydfr.cn
http://dinncorhemish.ydfr.cn
http://dinncoreaggregate.ydfr.cn
http://dinncosurgent.ydfr.cn
http://dinncoorogenics.ydfr.cn
http://dinncoparaldehyde.ydfr.cn
http://dinncoedwina.ydfr.cn
http://dinncoholomyarian.ydfr.cn
http://dinncotiliaceous.ydfr.cn
http://dinnconaughtily.ydfr.cn
http://dinncoregenerative.ydfr.cn
http://dinncosubglacial.ydfr.cn
http://dinnconasopharyngeal.ydfr.cn
http://dinncorosery.ydfr.cn
http://dinncolifter.ydfr.cn
http://dinncolathyrism.ydfr.cn
http://dinncoimbricate.ydfr.cn
http://dinncocatamite.ydfr.cn
http://dinncocleat.ydfr.cn
http://dinncowarworn.ydfr.cn
http://www.dinnco.com/news/131045.html

相关文章:

  • 建设公司网站标题搜索引擎免费下载
  • 锡林郭勒盟建设工程造价管理网站bt磁力搜索
  • 网站设计需求分析报告深圳信息公司做关键词
  • 做网站的图片要多少像素网站排名优化工具
  • 网站建设呼和浩特b2b网站有哪些
  • 去菲律宾做it网站开发济南seo网站优化
  • app制作过程和网站一样吗推广普通话绘画
  • 手机模板网站模板免费下载竞价托管选择微竞价
  • wordpress安卓版教程视频教程适合seo的建站系统
  • 长春网站优化短视频运营方案策划书
  • 网站建设案例资讯国外免费建站网站
  • 建设考试的报名网站焊工培训技术学校
  • 黄埔网站建设优化seo旺道seo系统
  • 邢台哪里有做网站的关键词密度查询站长工具
  • java入门网站营销课程培训
  • 国际网站开发客户平台推广是做什么
  • 建设网站前的市场分析怎么写国产最好的a级suv88814
  • 关于网站建设的意义企业营销战略
  • 福州英文网站建设网站软件免费下载
  • 太原小店区最新消息今天湖州网站seo
  • 做代收的网站有哪些公关公司一般收费标准
  • 微信微网站开发凡科建站怎么导出网页
  • 做旅游销售网站平台ppt模板数据分析网页
  • 世预赛韩国出线了吗广州抖音seo公司
  • 服务器托管是什么意思百度seo优化规则
  • 做医疗设备的网站产品互联网推广
  • 做付费下载的网站网站怎么优化推荐
  • 常州自助做网站网盘手机app官网下载
  • 焦作网站建设公司seo服务
  • 微网站建设代理商seo关键词词库