Game.Prefabs.NetLanePrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
A prefab component that represents a network lane configuration used by the game to spawn lane entities. NetLanePrefab declares lane-related components, manages dependencies (notably an optional PathfindPrefab), and, during late initialization, constructs and stores a set of EntityArchetypes for the various lane variants (area/edge/node, master/slave combinations). These archetypes are written into the NetLaneArchetypeData component on the prefab entity so that lane creation systems can instantiate lanes with the correct component sets.
Fields
public PathfindPrefab m_PathfindPrefab
Optional reference to a PathfindPrefab that this lane prefab depends on. If set, GetDependencies will add it to the provided prefab dependency list so that it is initialized/loaded before lane-related systems that require pathfinding data.
Properties
- (none declared)
This class does not declare any public properties. It relies on inherited PrefabBase behaviour and writes archetype information to components via LateInitialize.
Constructors
public NetLanePrefab()
Default parameterless constructor inherited from PrefabBase. The class does not declare any custom construction logic; initialization occurs in overridden lifecycle methods (GetDependencies, GetPrefabComponents, GetArchetypeComponents, LateInitialize).
Methods
public override void GetDependencies(List<PrefabBase> prefabs)
Adds referenced prefabs to the provided dependency list. Implementation:- Calls base.GetDependencies(prefabs).
-
If
m_PathfindPrefab
is not null, adds it toprefabs
. Use: ensures the PathfindPrefab is included in prefab loading order when present. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Collects component types that should be attached to the prefab itself. Implementation: - Calls base.GetPrefabComponents(components).
- Adds
NetLaneData
andNetLaneArchetypeData
(both ReadWrite) tocomponents
. -
If the base prefab does not already have a
SecondaryLane
component, addsSecondaryNetLane
(ReadWrite) tocomponents
. Use: controls what components the prefab entity will have so other systems can rely on them. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Collects component types contributed by this prefab to lane archetypes. Implementation: - Calls base.GetArchetypeComponents(components).
-
Adds
Curve
(ReadWrite) to the set. Use: called when assembling lane archetypes to ensure lanes include theCurve
component when appropriate. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Performs final initialization once the prefab entity exists in the EntityManager. Main responsibilities: - Collects component contributions from attached ComponentBase objects into a List
. - Builds a HashSet
base set and then constructs multiple EntityArchetypes for different lane roles: - m_LaneArchetype
- m_AreaLaneArchetype
- m_EdgeLaneArchetype
- m_NodeLaneArchetype
- m_EdgeSlaveArchetype
- m_NodeSlaveArchetype
- m_EdgeMasterArchetype
- m_NodeMasterArchetype
- Writes a NetLaneArchetypeData component to the prefab entity with these archetypes assigned. Notes:
- Each archetype is created by calling CreateArchetype with an accumulating set of ComponentTypes (adds Lane, AreaLane/EdgeLane/NodeLane, MasterLane/SlaveLane etc. as required).
-
It calls CreateArchetype repeatedly, and the helper clears the set after each creation.
-
private EntityArchetype CreateArchetype(EntityManager entityManager, List<ComponentBase> unityComponents, HashSet<ComponentType> laneComponents)
Helper that finalizes an archetype from a set of ComponentType entries plus contributions from component instances. Behavior: - Iterates over
unityComponents
and callsGetArchetypeComponents(laneComponents)
on each to let component instances add their archetype component types. - Adds
Created
andUpdated
(ReadWrite) components to the set. - Calls
entityManager.CreateArchetype(...)
with the accumulated components (after converting to an array viaPrefabUtils.ToArray
). - Clears
laneComponents
so the same HashSet can be reused for building the next archetype. - Returns the created
EntityArchetype
. Important: laneComponents is cleared by this method; callers should not expect previous entries to persist.
Usage Example
// Example: how LateInitialize prepares archetypes on the prefab entity.
// When the prefab system creates the prefab entity it will call LateInitialize;
// no explicit call is normally required. This snippet demonstrates the logical
// effect: after LateInitialize, NetLaneArchetypeData on the prefab entity
// contains archetypes for different lane variants.
[Preserve]
public class MyNetLanePrefabUser
{
// Suppose `prefabEntity` is an entity created from a NetLanePrefab.
// After prefab initialization:
private void OnPrefabReady(EntityManager em, Entity prefabEntity)
{
var archetypes = em.GetComponentData<NetLaneArchetypeData>(prefabEntity);
EntityArchetype laneArchetype = archetypes.m_LaneArchetype;
// Now you can use laneArchetype to create lane entities with the
// correct component set:
Entity lane = em.CreateEntity(laneArchetype);
// Set initial component data on the created lane entity as needed...
}
}
Additional notes:
- This prefab works with Unity.Entities (DOTS). The created archetypes are intended for fast instantiation of lane entities by game systems.
- PrefabUtils.ToArray is used to convert the HashSet