Game.Prefabs.NetPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
NetPrefab is a prefab helper for "net" prefabs (roads, tracks, power-lines, etc.). It extends PrefabBase to ensure network-related component types are included on the prefab and builds two entity archetypes used at runtime: one for node entities and one for edge entities. During LateInitialize it collects archetype requirements from child components, augments them with Created/Updated markers, creates the corresponding EntityArchetype objects, and stores them into the NetData component on the prefab entity (m_NodeArchetype and m_EdgeArchetype). This class coordinates which ConnectedNode / ConnectedEdge components are required depending on whether a Node or Edge component is present, enabling proper entity layout for network pieces.
Fields
- This class declares no private fields.
Notes: - The class operates on the NetData component found on the prefab entity; that component holds m_NodeArchetype and m_EdgeArchetype values that this class writes to via EntityManager.SetComponentData.
Properties
- This class declares no properties.
Constructors
public NetPrefab()
(implicit default constructor)
NetPrefab does not define an explicit constructor; the default parameterless constructor is used.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the NetData component to the prefab's component set in addition to any components gathered by the base PrefabBase. Callers use this to determine which component types belong on the prefab entity itself.
Behavior:
- Calls base.GetPrefabComponents(components).
- Adds ComponentType.ReadWrite
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Modifies an archetype component set to include connection helpers depending on whether the set already contains a Node or an Edge component. This ensures the correct companion component is present when constructing node- or edge-entity archetypes.
Behavior:
- Calls base.GetArchetypeComponents(components).
- If the incoming set contains ComponentType.ReadWrite
public override void LateInitialize(EntityManager entityManager, Entity entity)
Builds the node and edge archetypes for the prefab by querying child components for required archetype components and then creating and storing archetypes in the NetData component on the prefab entity.
Detailed steps:
1. Calls base.LateInitialize(entityManager, entity).
2. Collects all ComponentBase child components (GetComponents(list)).
3. Prepares two HashSet
Purpose: - Produces concrete EntityArchetype objects describing the memory layout for the runtime node and edge entities spawned from this prefab, ensuring they include required connection components and lifecycle markers.
Usage Example
// Example: registering prefab components and initializing archetypes
NetPrefab netPrefab = /* obtain reference to the NetPrefab MonoBehaviour */;
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity prefabEntity = /* the prefab entity associated with netPrefab */;
// Collect prefab component types
var prefabComponents = new HashSet<ComponentType>();
netPrefab.GetPrefabComponents(prefabComponents);
// Build runtime archetypes and store them into the NetData component on the prefab entity
netPrefab.LateInitialize(em, prefabEntity);
// After LateInitialize, NetData on prefabEntity contains m_NodeArchetype and m_EdgeArchetype
var netData = em.GetComponentData<NetData>(prefabEntity);
// netData.m_NodeArchetype and netData.m_EdgeArchetype can now be used to create runtime node/edge entities.
Additional notes: - This class expects child components to implement GetArchetypeComponents to contribute their layout requirements. - The Created and Updated components are added to ensure runtime lifecycle tracking on spawned node/edge entities. - LateInitialize must be called with a valid EntityManager and prefab entity; typically executed during prefab setup in the game's prefab initialization pipeline.