Skip to content

Game.Prefabs.StreetLightObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Prefab component class representing a street light object used by the ECS (Entity Component System). The class declares which ECS components are required for the prefab (a runtime data component and an archetype component) and initializes the entity's StreetLightData component with the prefab's layer value (m_Layer) during late initialization. It is intended for use with static/marker object prefabs (see ComponentMenu attribute).


Fields

  • public StreetLightLayer m_Layer
    Stores the street light's layer value configured on the prefab. This value is copied into the entity's StreetLightData.m_Layer during LateInitialize. The actual type StreetLightLayer is defined elsewhere in the codebase and typically indicates a categorization or rendering/behavior layer for the light.

Properties

  • This class does not declare any public properties.

Constructors

  • public StreetLightObject()
    Implicit default constructor generated by the compiler. No special construction logic is defined in the source.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime/persistent data component required by this prefab to the provided set. Implementation:
  • Calls components.Add(ComponentType.ReadWrite<StreetLightData>()) to ensure the entity will have a StreetLightData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds the archetype-level (often structural) component required for the prefab. Implementation:

  • Calls components.Add(ComponentType.ReadWrite<StreetLight>()) so entities created from this prefab include the StreetLight component in their archetype.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs late initialization of the created entity by writing prefab-configured values into the entity's component data:

  • Calls base.LateInitialize(entityManager, entity).
  • Creates a default StreetLightData, sets its m_Layer field from m_Layer, and writes it to the entity with entityManager.SetComponentData(entity, componentData).

Remarks: Both component additions use ComponentType.ReadWrite<T>(), indicating the components will be readable and writable on the entity.

Usage Example

// Example override that matches the prefab implementation: set the StreetLightData.m_Layer
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);

    StreetLightData componentData = default(StreetLightData);
    componentData.m_Layer = m_Layer; // copy prefab-configured layer into entity data
    entityManager.SetComponentData(entity, componentData);
}

Additional notes: - This prefab class depends on Unity.Entities types (EntityManager, Entity, ComponentType) and on project-specific types StreetLight, StreetLightData, and StreetLightLayer. - Ensure the referenced components (StreetLightData, StreetLight) are defined and registered appropriately in the mod/game code so the ECS knows how to handle them.