Game.Prefabs.AggregateNetPrefab
Assembly: Game
Namespace: Game.Prefabs
Type: public class
Base: PrefabBase
Summary:
AggregateNetPrefab is a prefab class used by the net/aggregate system. It ensures that the prefab exposes the required component types for runtime instantiation and creates a complete EntityArchetype for aggregate elements during LateInitialize. Key responsibilities:
- Add AggregateNetData to the prefab component list.
- Add AggregateElement to the archetype components.
- During LateInitialize, collect archetype components from contained ComponentBase instances, combine them with the Aggregate component and Created/Updated markers, create an EntityArchetype, and store it in AggregateNetData.m_Archetype so the runtime can instantiate aggregate elements efficiently.
Also decorated with the editor attribute [ComponentMenu("Net/Aggregate/")].
Fields
- (none declared in this class)
This class does not declare any private or public fields. It relies on inherited behavior and component data stored on the prefab entity (AggregateNetData).
Properties
- (none declared in this class)
No properties are explicitly declared on AggregateNetPrefab itself.
Constructors
public AggregateNetPrefab()
Default parameterless constructor (implicit). The class relies on the base PrefabBase constructor; no custom construction logic is provided.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the components that must exist on the prefab entity. Implementation:- Calls base.GetPrefabComponents(components).
-
Adds ComponentType.ReadWrite
() so prefab entities include the AggregateNetData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the components that should be included in the archetype for aggregate elements. Implementation: - Calls base.GetArchetypeComponents(components).
-
Adds ComponentType.ReadWrite
() to the provided set. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Performs final initialization when the prefab is being prepared for runtime use. Implementation details: - Calls base.LateInitialize(entityManager, entity).
- Collects all ComponentBase instances attached to this prefab via GetComponents(list).
- Builds a HashSet
starting with ComponentType.ReadWrite (). - Invokes each ComponentBase.GetArchetypeComponents(hashSet) to collect component types required for aggregate elements.
- Adds Created and Updated component types (ComponentType.ReadWrite
(), ComponentType.ReadWrite ()). - Retrieves AggregateNetData from the prefab entity, creates an EntityArchetype from the accumulated component types via entityManager.CreateArchetype(PrefabUtils.ToArray(hashSet)), and stores that archetype back into AggregateNetData.m_Archetype using entityManager.SetComponentData.
Notes: - This method expects ComponentBase.GetArchetypeComponents implementations to populate the hash set with component types the component contributes to element archetypes. - The resulting archetype is intended for creating aggregate Element entities at runtime that carry the correct component set.
Usage Example
// Typical usage: runtime systems use the archetype prepared by LateInitialize.
// After the prefab has been initialized by the prefab system:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity prefabEntity = /* resolved prefab entity for AggregateNetPrefab */;
// Read the archetype prepared in LateInitialize
AggregateNetData data = em.GetComponentData<AggregateNetData>(prefabEntity);
EntityArchetype elementArchetype = data.m_Archetype;
// Create a new aggregate element entity using that archetype
Entity element = em.CreateEntity(elementArchetype);
// You can now set required component data on 'element' (Aggregate, AggregateElement, Created, Updated, etc.)
Additional implementation notes:
- The prefab class depends on PrefabUtils.ToArray to convert the HashSet