Skip to content

Game.Prefabs.ObjectSubLanes

Assembly:
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
{{ This component is attached to object prefabs to define one or more "sub-lanes" that belong to the object. Each entry in m_SubLanes references a lane prefab and positional/index data (m_LanePrefab, m_NodeIndex). The component alters prefab dependencies and the ECS archetype so that created instances include the appropriate SubLane components when required. It also forces the prefab system to ignore unlock dependencies for this component. }}


Fields

  • public ObjectSubLaneInfo[] m_SubLanes
    {{ An array of ObjectSubLaneInfo entries describing each sub-lane for this object. Each ObjectSubLaneInfo typically contains at least a reference to a lane prefab (m_LanePrefab) and a node index (m_NodeIndex). This array is used by GetDependencies to add lane prefabs to the prefab dependency list and inspected by GetArchetypeComponents to determine whether to include a Game.Net.SubLane component on the archetype. }}

Properties

  • public override bool ignoreUnlockDependencies => true
    {{ This override tells the prefab system to ignore unlock-dependency checks for prefabs that include this component. In practice it means the prefab will be treated as available regardless of any 'unlock' relationships that might otherwise prevent loading. }}

Constructors

  • public ObjectSubLanes()
    {{ Default parameterless constructor (no custom initialization is provided in source). Instances are typically configured via the inspector or by assigning m_SubLanes in code. }}

Methods

  • public override void GetDependencies(System.Collections.Generic.List<PrefabBase> prefabs)
    {{ Adds referenced lane prefabs from each ObjectSubLaneInfo (m_LanePrefab) to the provided prefabs list. This ensures the lane prefabs that the sub-lanes reference are loaded/available when this object prefab is processed. The method first calls base.GetDependencies(prefabs) before adding sub-lane prefabs. }}

  • public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    {{ Adds ComponentType.ReadWrite() to the provided set of prefab components. This indicates that instances of the prefab require the SubLane component at the prefab/component level so that the entity will have read/write access to SubLane data. }}

  • public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    {{ Inspects the m_SubLanes array; if any ObjectSubLaneInfo has m_NodeIndex.x != m_NodeIndex.y (i.e., the sub-lane spans different node indices), the method adds ComponentType.ReadWrite() to the archetype components. This conditional addition ensures that archetypes include the networked SubLane component only when needed (for sub-lanes that span nodes), avoiding unnecessary components on all instances. }}

Usage Example

// Example: Inspecting and logging configured sub-lanes on a prefab instance
void PrintSubLanes(ObjectSubLanes subLanesComponent)
{
    if (subLanesComponent == null || subLanesComponent.m_SubLanes == null)
        return;

    for (int i = 0; i < subLanesComponent.m_SubLanes.Length; i++)
    {
        var info = subLanesComponent.m_SubLanes[i];
        // m_LanePrefab and m_NodeIndex exist on ObjectSubLaneInfo (as referenced by this component)
        var prefabName = info.m_LanePrefab != null ? info.m_LanePrefab.name : "null";
        UnityEngine.Debug.Log($"SubLane[{i}] prefab={prefabName} nodeIndex={info.m_NodeIndex}");
    }
}

{{ Notes: - ObjectSubLaneInfo is a supporting struct/class (not shown here) and is expected to expose at least m_LanePrefab and m_NodeIndex fields. - GetDependencies ensures that lane prefabs referenced by sub-lanes are included in the prefab loading chain. - The conditional addition in GetArchetypeComponents helps keep ECS archetypes minimal unless per-entity SubLane networked data is required. - This component is intended to be set up in the prefab inspector for object prefabs (e.g., props, decorations) that should spawn or reference in-world lane segments. }}