entity

Entity is one of the three main elements of the physical components of the system architecture. They represent the game or program personal "things." Neither a physical nor behavioral data; instead, which identifies the data which belong together. The system provides a behavior component to store data.

ID is a physically nature. You can use it as a super lightweight GameObject , by default do not even have names. Entity ID is stable. They are only stable way to store a reference to another component or entity.

A EntityManager manage a world all entities. EntityManager maintenance entity list and organize data associated with an entity to obtain the best performance.

Although there is no type of entity, but the entity set may be classified according to the type of data components associated with them in. When you create an entity and add components, EntityManager tracks unique combination of components on existing entities. This unique combination is called a prototype . When you add the component to the entity, EntityManager creates EntityArchetype structure. You can use an existing EntityArchetypes to create a new entity in line with the prototype. You can also create EntityArchetype in advance and use it to create an entity.

Creating entity

The easiest way to create an entity is to use the Unity editor. You can set placed in the scene of game objects and entities to convert to preform at runtime. For the more dynamic part of the game or program, you can create a system, create derivative multiple entities in the job. Finally, you can use EntityManager.CreateEntity time you create a solid one function.

Use EntityManager created entity

Use EntityManager.CreateEntity to create one entity function. Entity created in the same EntityManager in the World.

You can create one by one entity in the following ways:

  • Use ComponentType create an entity that contains the components of an array of objects.
  • Use EntityArchetype create an entity that contains components.
  • Use Instantiate copying an existing entity (including its current data)
  • Create an entity with no assembly, then add components to it. (You can add components immediately, you can also add other components.)

You can also create more than one entity:

  • Use CreateEntity use the new prototype filled with the same entity NativeArray.
  • Use Instantiate filled copy of an existing entity to NativeArray, including its current data.
  • Use CreateChunk explicitly created using a block of the specified number of prototype filled entity.

Add and remove components

After creating an entity, you can add or remove components do this, the affected entity prototype will change, we must change the EntityManager mobile data to a new block of memory, and an array of compression components in the original block.

Lead to changes in the structure of the entity change (ie, add or remove components to change the values and the destruction SharedComponentData entity) can not be completed within the Job, because these operations may cause Job data being processed is invalid. But to add commands to EntityCommandBuffer make these types of changes, and execute the command buffer after the Job is completed.

EntityManager provides remove components from a single entity and all entities in NativeArray functions. For more information, see Component

Iteration entity

Iteration all entities with a matching set of components, ECS is the core architecture. See access data entity .

Guess you like

Origin www.cnblogs.com/longsl/p/11318764.html