Game.Prefabs.Modes.ModeSetting
Assembly:
Assembly-CSharp (typical Unity project assembly)
Namespace:
Game.Prefabs.Modes
Type:
class
Base:
PrefabBase
Summary:
ModeSetting is a prefab class used by the game's mod/prefab system to configure global "mode" settings that modify many simulation systems (demand, taxes, resources, subsidies, etc.). It serializes a set of editable fields that are written into an ECS singleton (ModeSettingData) when the mode is applied, and it also manages child ModePrefabs which can be local (LocalModePrefab) or global/entity-query based (EntityQueryModePrefab). The class provides lifecycle hooks to initialize, store defaults, restore defaults, and apply the mode to the live simulation using an EntityManager and PrefabSystem.
Fields
-
public bool m_Enable
Controls whether the systems defined by this mode are enabled. When applied, this value is written into the ModeSettingData singleton that downstream systems read. -
public float2 m_ResidentialDemandWeightsSelector
Weights for residential demand factors. The prefab tooltip indicates using x for negative and y for positive factors. Default expected to be (1,1) to leave behavior unchanged. -
public float m_CommercialTaxEffectDemandOffset
Offset applied to commercial demand from tax factor. Tax factor expected in range [-1, 1]. -
public float m_IndustrialOfficeTaxEffectDemandOffset
Offset applied to industrial and office demand from tax factor. Tax factor expected in range [-1, 1]. -
public float m_ResourceDemandPerCitizenMultiplier
Multiplier for resource demand per citizen (default 1 = normal demand). -
public float3 m_TaxPaidMultiplier
Multiplier applied to the amount of tax paid: (x = citizens, y = commercial, z = industrial+office). Does not affect player income or city statistics; it modifies internal values used by systems. -
public bool m_SupportPoorCitizens
If true, the "give money to poor citizens" behavior is active. -
public int m_MinimumWealth
If a citizen's wealth is below this threshold, they will be given money (when support is enabled) until they reach this value. -
public bool m_EnableGovernmentSubsidies
Enable government subsidy behavior. -
public int2 m_MoneyCoverThreshold
Two-component int: player money level where subsidies start (x) and maximum cover threshold (y). -
public int m_MaxMoneyCoverPercentage
Maximum percent of expenses that government subsidies cover (0 = no cover, 100 = full cover, values >100 allowed per code). -
public bool m_EnableAdjustNaturalResources
Enable adjustment of natural resources (Groundwater, Fertility, Ore, Oil). -
public float m_InitialNaturalResourceBoostMultiplier
Initial multiplier for natural resources: 0 = no resources, 1 = normal. -
public int m_PercentOreRefillAmountPerDay
Percentage of ore refill per day (0 = no refill, 100 = full refill in 1 day). -
public int m_PercentOilRefillAmountPerDay
Percentage of oil refill per day (0 = no refill, 100 = full refill in 1 day). -
public List<ModePrefab> m_ModePrefabs
List of child ModePrefabs defined on this prefab. Elements can be LocalModePrefab or EntityQueryModePrefab. These are processed during Initialize and when applying/restoring/storing defaults. -
private List<LocalModePrefab> m_LocalModePrefabs
Internal list built at Initialize containing only the LocalModePrefab instances from m_ModePrefabs. Local mode prefabs are applied directly via ApplyModeData(entityManager, prefabSystem). -
private List<EntityQueryModePrefab> m_GlobalModePrefabs
Internal list built at Initialize containing only the EntityQueryModePrefab instances from m_ModePrefabs. These require an EntityQuery to locate matching entities and are applied via jobs (JobHandle) when ApplyMode is called.
Properties
- None declared on ModeSetting (no C# properties). The class uses public fields and internal lists instead.
Constructors
public ModeSetting()
Implicit default constructor inherited from PrefabBase. No custom construction logic is defined in this class; initialization logic happens in Initialize(EntityManager, Entity).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required component types that this prefab will touch. Implementation adds ComponentType.ReadWrite() to the provided set. Note: the implementation adds GameModeSettingData; elsewhere the class reads/writes ModeSettingData as a singleton — be aware of this naming difference when integrating (it may reflect two related components or be a naming inconsistency in game code). -
public override void GetDependencies(List<PrefabBase> prefabs)
If m_ModePrefabs is populated, each entry is added to the prefabs dependency list. Ensures referenced child mode prefabs are known to the prefab system. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called by the prefab system to prepare runtime structures. It creates new lists for m_LocalModePrefabs and m_GlobalModePrefabs and iterates m_ModePrefabs to separate LocalModePrefab and EntityQueryModePrefab instances into the internal lists. If m_ModePrefabs is null the method returns early. -
public void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Restores default data for this mode and its children: - Sets the ModeSettingData singleton's m_Enable to false (creates a query for ModeSettingData singleton and writes the data).
- Calls RestoreDefaultData on each LocalModePrefab.
- For each EntityQueryModePrefab, creates an EntityQuery using GetEntityQueryDesc(); if the query is not empty, it converts results to a NativeArray
(Allocator.TempJob), calls RestoreDefaultData(entityManager, ref entities, prefabSystem) on that global prefab and disposes the array. -
Important: uses Allocator.TempJob and disposes arrays; keep in mind TempJob must be disposed within a frame.
-
public void StoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Stores default data for global (entity-query) mode prefabs: -
For each EntityQueryModePrefab, creates the matching EntityQuery, and if not empty, converts to a NativeArray
with Allocator.TempJob, calls StoreDefaultData(entityManager, ref requestedQuery, prefabSystem) and disposes the array. -
public JobHandle ApplyMode(EntityManager entityManager, PrefabSystem prefabSystem, JobHandle deps)
Applies this mode to the running simulation: - Finds the ModeSettingData singleton entity and writes a ModeSettingData populated from the prefab's public fields (m_Enable, demand/tax/resource settings, subsidy settings, natural resource adjustments).
- Calls ApplyModeData(entityManager, prefabSystem) on each LocalModePrefab to apply local changes immediately.
- For each EntityQueryModePrefab, creates an EntityQuery; if not empty, calls ApplyModeData(entityManager, requestedQuery, deps) which returns a JobHandle and chains dependencies.
- Returns the final JobHandle for jobs started by global mode prefabs.
-
Note: method mixes immediate main-thread component setting (SetComponentData) with jobified changes returned via JobHandle. Callers should schedule/complete returned handle appropriately.
-
public virtual void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Intended to record what changed when this mode is applied; current implementation: - Iterates local mode prefabs (but does nothing in the provided body — reserved/hooked for overrides).
- Iterates global mode prefabs and creates/Immediately disposes an entity array from each prefab's entity query. This appears to ensure queries are evaluated or to force some prefab-system bookkeeping; no data is stored in this implementation.
Usage Example
// Typical usage inside a Prefab system or initialization routine
// entityManager and prefabSystem are provided by the game's mod/prefab environment
ModeSetting modePrefab = /* obtain ModeSetting prefab instance from PrefabSystem */;
modePrefab.Initialize(entityManager, prefabEntity);
// Store defaults for global prefabs once (optional)
modePrefab.StoreDefaultData(entityManager, prefabSystem);
// Apply the mode (schedules jobs for global mode prefabs and returns dependencies)
JobHandle deps = default;
deps = modePrefab.ApplyMode(entityManager, prefabSystem, deps);
// Later, if needed, restore defaults
modePrefab.RestoreDefaultData(entityManager, prefabSystem);
Additional notes and tips: - ModeSetting writes to an ECS singleton component of type ModeSettingData (code uses ModeSettingData for reads/writes when applying/restoring, but GetPrefabComponents adds GameModeSettingData — verify which component type is used in your game version). - Be careful with NativeArray allocations using Allocator.TempJob — they must be disposed within the same frame or as required by the job API. - ApplyMode returns a JobHandle for jobs started by EntityQueryModePrefabs. If you need deterministic ordering, chain or Complete the returned handle appropriately. - If m_ModePrefabs is null or empty, many operations are no-ops aside from writing the ModeSettingData fields. - This prefab affects simulation systems but does not directly change player-visible statistics like “player income” for taxes — see m_TaxPaidMultiplier tooltip.