合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
Class/Struct Info |
|---|
public readonly ref struct EntityFastAccess EntityFastAccess定义为只读引用结构体,保证了高性能的组件访问优化,同时确保内存安全。 |
Name | Type | Description |
|---|---|---|
Id | int | 只读属性,实体标识。 |
Tags | ITags | 实体具有的标签集合。 |
IsDeleted | bool | 数据删除标识:
|
Archetype | Archetype | 实体所属原型。 |
var world = new IECSWorld(); var entity = world.CreateEntity(new PgdPosition()); var fastAccess = entity.EntityFastAccess; // EntityFastAccess的属性与其实体相同 fastAccess.Id; // 等于entity.Id fastAccess.Tags; // 等于entity.Tags fastAccess.IsDeleted; // 等于entity.IsDeleted() fastAccess.Archetype; // 等于entity.Archetype
Method |
|---|
bool Has<T>() 判断实体是否拥有指定泛型组件,最多支持1个泛型。 T为IComponent。 |
Return
Type | Description |
|---|---|
bool |
|
Sample Code
var world = new IECSWorld(); var entity = world.CreateEntity(new PgdPosition()); var fastAccess = entity.EntityFastAccess; // 判断实体是否拥有指定组件,仅支持一个组件 fastAccess.Has<PgdPosition>(); // true fastAccess.Has<PgdRotation>(); // false
Method |
|---|
ref T Get<T>() 获取指定泛型组件,最多支持1个泛型。 T为IComponent。 |
Return
Type | Description |
|---|---|
ref T | 返回指定泛型组件的引用。 |
Sample Code
var world = new IECSWorld(); var entity = world.CreateEntity(new PgdPosition()); // 此时PgdPosition组件值为(0,0,0) var fastAccess = entity.EntityFastAccess; // 获取组件引用,可直接修改组件值 fastAccess.Get<PgdPosition>().x = 1; // 此时PgdPosition组件值为(1,0,0)
Method |
|---|
bool TryGet<T>(out T value) 获取指定泛型组件,有安全性检验,最多支持1个泛型。 T为IComponent。 |
Parameters
Name | Type | Description |
|---|---|---|
value | T | 接收返回的组件。 |
Return
Type | Description |
|---|---|
bool |
|
Sample Code
var world = new IECSWorld();
var entity = world.CreateEntity(new PgdPosition());
var fastAccess = entity.EntityFastAccess;
// 安全获取组件值,成功获取返回true,没有对应组件则返回false
if(fastAccess.TryGet<PgdPosition>(out var pos))
{
/*获取成功处理*/
}
else
{
/*没有组件处理*/
} Method |
|---|
string ToString() 将实体标识以字符串形式返回。 |
Return
Type | Description |
|---|---|
string | 实体标识。 |
Sample Code
var world = new IECSWorld(); var entity = world.CreateEntity(1); var fastAccess = entity.EntityFastAccess; // 打印实体Id fastAccess.ToString(); // "EntityId: 1"
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功