Game.Prefabs.Modes.MilestonesMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
MilestonesMode is a prefab component used to map designer-configured milestone values (from MilestonePrefab assets) into runtime ECS MilestoneData components. It contains an array of ModeData entries that target specific MilestonePrefab assets and supply mode-specific overrides such as reward, dev tree points, map tiles, loan limit and XP required. The class implements lifecycle overrides to record referenced entities and to apply or restore mode-specific data to the corresponding ECS entities via an EntityManager and a PrefabSystem.
Fields
-
public ModeData[] m_ModeDatas
Holds the list of mode entries. Each ModeData links a MilestonePrefab to a set of values that should be applied to that milestone's MilestoneData component when the mode is activated. -
public class ModeData
public MilestonePrefab m_Prefab
Reference to the MilestonePrefab asset that this entry targets. Must be non-null; otherwise the code logs a critical error and skips the entry.public int m_Reward
Reward value to write into the MilestoneData.m_Reward field when applied.public int m_DevTreePoints
Dev tree points override for MilestoneData.m_DevTreePoints.public int m_MapTiles
Map tiles override for MilestoneData.m_MapTiles.public int m_LoanLimit
Loan limit override for MilestoneData.m_LoanLimit.public int m_XpRequried
XP required override for MilestoneData.m_XpRequried.
Properties
- None.
Constructors
public MilestonesMode()
Default public constructor (inherited behavior). Typical usage is via the prefab/inspector; no custom constructor logic is defined in this class.
Methods
-
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates over m_ModeDatas, resolves each referenced MilestonePrefab to an Entity using prefabSystem.GetEntity(...), and calls entityManager.GetComponentData(entity). This ensures that the milestone entity/component is registered/accessed so that any change tracking systems are aware of the dependency. If a ModeData entry has a null m_Prefab the method logs a critical error and skips that entry. -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Applies the configured override values from each ModeData into the corresponding MilestoneData ECS component. For each entry it resolves the Entity for the referenced MilestonePrefab, reads the existing MilestoneData, updates its fields (m_Reward, m_DevTreePoints, m_MapTiles, m_LoanLimit, m_XpRequried) with the ModeData values, and writes the updated component back with entityManager.SetComponentData(...). Null m_Prefab entries are logged and skipped. -
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Restores the milestone entity's MilestoneData fields back to the defaults defined on the MilestonePrefab asset. For each ModeData entry it resolves the prefab entity and copies the values from milestonePrefab (the asset fields) into the MilestoneData component, then writes them back to the entity. Null m_Prefab entries are logged and skipped.
Usage Example
// Example: apply configured milestone mode data at runtime (e.g. when a mode is activated)
// Assume `mode` is a reference to a MilestonesMode prefab instance (inspector or loaded prefab),
// and entityManager / prefabSystem are available in your context.
MilestonesMode mode = /* obtain prefab instance */;
EntityManager entityManager = /* obtain EntityManager */;
PrefabSystem prefabSystem = /* obtain PrefabSystem */;
// Apply the mode overrides to all referenced milestone entities
mode.ApplyModeData(entityManager, prefabSystem);
// To restore defaults later:
mode.RestoreDefaultData(entityManager, prefabSystem);
Notes: - The class expects MilestonePrefab and MilestoneData types to exist in the project. MilestonePrefab provides default values (used by RestoreDefaultData) and MilestoneData is the ECS component that stores live values. - If a ModeData entry's m_Prefab is null the code logs a critical error via ComponentBase.baseLog and skips that entry to avoid exceptions.