Skip to content

Game.Prefabs.SpawnableLane

Assembly:
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
SpawnableLane is a prefab component used to define alternative lane prefabs that can be spawned on a net (road) lane. It exposes an array of placeholder lane prefabs, a spawn probability (0–100) and an optional randomization group to choose from. The component registers a runtime ECS component (SpawnableObjectData) for use by the spawning/placement pipeline. The ComponentMenu attribute places the component under the "Net/" menu in the editor and references NetLanePrefab for the inspector menu filtering.


Fields

  • public NetLanePrefab[] m_Placeholders
    Holds one or more lane prefabs that may be spawned in place of the base lane. These are added to the prefab dependency list so they are built/loaded with the parent prefab.

  • public int m_Probability = 100
    Spawn probability (0–100) for this spawnable lane. Marked with UnityEngine.Range so it's exposed as a slider in the inspector. A value of 100 means always considered (subject to other game logic), lower values reduce chance of spawning.

  • public GroupPrefab m_RandomizationGroup
    Optional reference to a GroupPrefab used to randomize or group placeholder choices. If set, the group prefab is also added to the prefab dependency list.

Properties

  • This class does not expose any public properties.

Constructors

  • public SpawnableLane()
    No explicit constructor is defined in the source; the default parameterless constructor is used. Initialization of default field values occurs inline (e.g., m_Probability = 100).

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs) : System.Void
    Adds all placeholder prefabs and the optional randomization group to the provided dependency list. Calls base.GetDependencies(prefabs) first. This ensures the prefab build/serialize system knows about and includes referenced prefabs.

  • public override void GetPrefabComponents(HashSet<ComponentType> components) : System.Void
    Registers runtime ECS prefab components required by this component by adding ComponentType.ReadWrite(). This indicates that entities spawned from this prefab will include SpawnableObjectData as a read/write component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components) : System.Void
    Defined but empty in this class. No additional archetype components are added here; archetype component registration (if any) is handled elsewhere or via GetPrefabComponents.

Usage Example

// Typical implementation is exactly as in the source: ensure placeholders and group are added to dependencies.
public override void GetDependencies(List<PrefabBase> prefabs)
{
    base.GetDependencies(prefabs);

    // Ensure every placeholder prefab is included in build/load
    for (int i = 0; i < m_Placeholders.Length; i++)
    {
        prefabs.Add(m_Placeholders[i]);
    }

    // Include the randomization group if assigned
    if (m_RandomizationGroup != null)
    {
        prefabs.Add(m_RandomizationGroup);
    }
}

Additional notes: - Because this component adds SpawnableObjectData to prefab components, spawning systems that rely on that ECS component will recognize and process prefabs containing this component. - The ComponentMenu attribute helps place this component in the editor under "Net/". The Range attribute on m_Probability gives a convenient inspector slider to tune spawn chance.