Skip to content

Game.Prefabs.TimeSettingsPrefab

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class

Base:
PrefabBase

Summary:
Prefab that exposes time-related settings (currently the number of days per year) and ensures the corresponding ECS component (TimeSettingsData) is added to entities created from this prefab. When the prefab is initialized into an Entity, it writes the configured m_DaysPerYear value into the TimeSettingsData component.


Fields

  • public int m_DaysPerYear = 12
    Default number of days per year used by this prefab. This value is copied into the TimeSettingsData component during LateInitialize. You can change this in the prefab (inspector or via code) to control the game's calendar configuration for entities created from this prefab.

Properties

  • None declared on this type.

Constructors

  • public TimeSettingsPrefab()
    Implicit parameterless constructor (no custom initialization beyond the declared field defaults).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that this prefab requires to the provided set. Implementation calls the base method and then adds ComponentType.ReadWrite<TimeSettingsData>(), indicating that entities created from this prefab will include a writable TimeSettingsData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Overrides the base method but does not add any additional archetype components beyond what the base type provides. Present for completeness and future extension.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called when the prefab is being converted/initialized into an ECS Entity. This method calls the base implementation and then writes a new TimeSettingsData instance to the entity via entityManager.SetComponentData, setting m_DaysPerYear to the prefab's m_DaysPerYear value.

Usage Example

// Example: customizing the prefab value in code before the prefab is used
var prefab = new TimeSettingsPrefab();
prefab.m_DaysPerYear = 360; // set desired days per year

// When the game converts this prefab into an Entity, LateInitialize will run:
// entityManager.SetComponentData(entity, new TimeSettingsData { m_DaysPerYear = prefab.m_DaysPerYear });

// Example: reading the value back from the entity after initialization
TimeSettingsData settings = entityManager.GetComponentData<TimeSettingsData>(entity);
Debug.Log($"Days per year: {settings.m_DaysPerYear}");

Notes: - TimeSettingsData must be a defined ECS IComponentData struct elsewhere in the game code. This prefab only ensures that component is added and populated. - GetArchetypeComponents currently does not add extra archetype components; if additional runtime or archetype-level components are required in the future, this method can be extended.