Boat Attack使用了Universal RP的许多新图形功能,可以用于探索 Universal RP 的使用方式和技巧。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

1.7 KiB

uid
ecs-entity-manager

EntityManager

The EntityManager owns EntityData, EntityArchetypes, SharedComponentData and EntityQuery.

EntityManager is where you find APIs to create entities, check if an entity is still alive, instantiate entities and add or remove components.

// Create an entity with no components on it
var entity = EntityManager.CreateEntity();

// Adding a component at runtime
EntityManager.AddComponent(entity, new MyComponentData());

// Get the ComponentData
MyComponentData myData = EntityManager.GetComponentData<MyComponentData>(entity);

// Set the ComponentData
EntityManager.SetComponentData(entity, myData);

// Removing a component at runtime
EntityManager.RemoveComponent<MyComponentData>(entity);

// Does the entity exist and does it have the component?
bool has = EntityManager.HasComponent<MyComponentData>(entity);

// Is the entity still alive?
bool has = EntityManager.Exists(entity);

// Instantiate the entity
var instance = EntityManager.Instantiate(entity);

// Destroy the created instance
EntityManager.DestroyEntity(instance);
// EntityManager also provides batch APIs
// to create and destroy many entities in one call. 
// They are significantly faster 
// and should be used where ever possible
// for performance reasons.

// Instantiate 500 entities and write the resulting entity IDs to the instances array
var instances = new NativeArray<Entity>(500, Allocator.Temp);
EntityManager.Instantiate(entity, instances);

// Destroy all 500 entities
EntityManager.DestroyEntity(instances);