Skip to content

Game.LeisureParametersPrefab

Assembly:
Assembly-CSharp (inferred)

Namespace:
Game.Prefabs

Type:
class

Base:
PrefabBase

Summary:
Prefab that holds configuration for leisure/tourist behaviour and links to related event prefabs. This prefab is used during initialization to populate a LeisureParametersData component on the ECS entity for leisure-related systems (e.g., which events to spawn, randomness factor, and tourist consumption rates).


Fields

  • public EventPrefab m_TravelingEvent
    Reference to the EventPrefab used for traveling events. Added to dependencies and resolved to an entity in LateInitialize.

  • public EventPrefab m_AttractionPrefab
    Reference to the EventPrefab used for attraction events. Added to dependencies and resolved to an entity in LateInitialize.

  • public EventPrefab m_SightseeingPrefab
    Reference to the EventPrefab used for sightseeing events. Added to dependencies and resolved to an entity in LateInitialize.

  • public int m_LeisureRandomFactor = 512
    Randomness scaling factor used by leisure systems. Default value is 512.

  • public int m_TouristLodgingConsumePerDay = 100
    The lodging resource consumption rate per tourist per day. Default value is 100.

  • public int m_TouristServiceConsumePerDay = 100
    The service resource consumption rate per tourist per day. Default value is 100.

Properties

  • None. This prefab exposes fields and overrides lifecycle methods but does not define public C# properties.

Constructors

  • public LeisureParametersPrefab()
    Default constructor (instantiated by Unity/editor). Use the inspector to assign EventPrefab references and tweak numeric parameters. No custom runtime initialization occurs in the constructor; initialization into ECS is done in LateInitialize.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds referenced EventPrefab instances (m_TravelingEvent, m_AttractionPrefab, m_SightseeingPrefab) to the provided prefabs list so the prefab system can load/initialize those prefabs first.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the LeisureParametersData component type to the set of components that this prefab will provide on its entity (via ComponentType.ReadWrite).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Override present but does not add additional archetype components in this implementation. It calls the base implementation.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Resolves the EventPrefab references into entities using the PrefabSystem and writes a LeisureParametersData component to the provided entity. Fields written:

  • m_TravelingPrefab (entity)
  • m_AttractionPrefab (entity)
  • m_SightseeingPrefab (entity)
  • m_LeisureRandomFactor
  • m_TouristLodgingConsumePerDay
  • m_TouristServiceConsumePerDay

Notes: - Relies on a PrefabSystem existing on the World to resolve EventPrefab -> Entity via GetEntity(EventPrefab). - Writes the component using entityManager.SetComponentData(entity, componentData).

Usage Example

// Example of the same LateInitialize behavior shown in the prefab.
// This runs when the prefab is turned into an ECS entity and populates the data component.
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);
    var prefabSystem = entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();

    LeisureParametersData componentData = default;
    componentData.m_TravelingPrefab = prefabSystem.GetEntity(m_TravelingEvent);
    componentData.m_AttractionPrefab = prefabSystem.GetEntity(m_AttractionPrefab);
    componentData.m_SightseeingPrefab = prefabSystem.GetEntity(m_SightseeingPrefab);
    componentData.m_LeisureRandomFactor = m_LeisureRandomFactor;
    componentData.m_TouristLodgingConsumePerDay = m_TouristLodgingConsumePerDay;
    componentData.m_TouristServiceConsumePerDay = m_TouristServiceConsumePerDay;

    entityManager.SetComponentData(entity, componentData);
}

Additional notes: - Ensure EventPrefab references are assigned in the prefab asset in the editor so dependencies are resolved correctly. - The related ECS struct LeisureParametersData must be present in the game code; this prefab maps its inspector values to that component.