Skip to content

Game.Prefabs.Modes.LeisureProviderMode

Assembly:
Assembly-CSharp (typical Unity game assembly)
Namespace:
Game.Prefabs.Modes

Type:
class

Base:
LocalModePrefab

Summary:
LeisureProviderMode is a prefab component used to apply mode-specific adjustments to leisure provider prefabs (e.g., parks, leisure buildings). It holds an array of ModeData entries that reference BuildingPrefab instances and an efficiency multiplier. At runtime it records references to the underlying ECS entities, applies efficiency multipliers to the corresponding LeisureProviderData component, and can restore the original efficiency values from the source LeisureProvider component. The component logs a critical message if a referenced prefab does not contain a LeisureProvider component.


Fields

  • public ModeData[] m_ModeDatas
    An array of ModeData entries. Each ModeData contains a BuildingPrefab reference and a multiplier that will be applied to the target prefab's LeisureProviderData.m_Efficiency when ApplyModeData is called. This field is intended to be populated in the prefab inspector.

  • public class ModeData

  • public BuildingPrefab m_Prefab
    Reference to the BuildingPrefab whose LeisureProvider component will be targeted.
  • public float m_EfficiencyMultifier
    Multiplier applied to the target's m_Efficiency when ApplyModeData runs. Typical values are >= 0; 1.0 means no change.

Notes: - ModeData is a serializable nested class used for configuring which prefabs are affected and by how much. - The code expects each referenced BuildingPrefab to contain a LeisureProvider component; otherwise a critical log is emitted and that entry is skipped.

Properties

This type does not declare any public or private C# properties.

Constructors

  • public LeisureProviderMode()
    Default constructor (compiler-provided). Instances are typically created by Unity when loading or instantiating prefabs that include this component.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Records/refs the ECS entities for the configured prefabs by calling PrefabSystem.GetEntity for each referenced LeisureProvider.prefab and then reading the LeisureProviderData component via EntityManager.GetComponentData(entity). This ensures the ECS component is touched/registered for later modification. If the referenced BuildingPrefab does not contain a LeisureProvider component, a critical log is emitted and that entry is skipped.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    Applies the configured efficiency multiplier to each referenced prefab's LeisureProviderData:

  • Retrieves the LeisureProvider component from the BuildingPrefab to find the prefab entity.
  • Reads LeisureProviderData from the entity.
  • Multiplies componentData.m_Efficiency by modeData.m_EfficiencyMultifier, casts the result to int, and writes it back with EntityManager.SetComponentData. Notes:
  • The multiplication result is cast to int, so fractional changes are rounded/truncated by the cast.
  • If the LeisureProvider component is missing on a configured prefab, the entry is skipped and a critical log is emitted.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    Restores the original efficiency value using the source LeisureProvider component:

  • Retrieves the LeisureProvider component from the BuildingPrefab.
  • Reads the current LeisureProviderData from the entity and sets componentData.m_Efficiency = component.m_Efficiency (the default value stored on the MonoBehaviour/component on the prefab).
  • Writes the restored value back to the entity with EntityManager.SetComponentData. If the LeisureProvider component is missing on a configured prefab, the entry is skipped and a critical log is emitted.

Usage Example

// Example: configure a LeisureProviderMode instance and apply a 20% efficiency boost
var leisureMode = someGameObject.GetComponent<Game.Prefabs.Modes.LeisureProviderMode>();
leisureMode.m_ModeDatas = new Game.Prefabs.Modes.LeisureProviderMode.ModeData[] {
    new Game.Prefabs.Modes.LeisureProviderMode.ModeData {
        m_Prefab = leisureBuildingPrefab,      // assign a BuildingPrefab reference
        m_EfficiencyMultifier = 1.2f           // +20% efficiency
    }
};

// Later, when switching modes:
leisureMode.ApplyModeData(entityManager, prefabSystem);

// To restore defaults:
leisureMode.RestoreDefaultData(entityManager, prefabSystem);

Additional notes and recommendations: - Ensure m_ModeDatas is properly populated in the prefab inspector or via code. Missing LeisureProvider components on the referenced BuildingPrefabs are logged and skipped. - Be aware of the int cast in ApplyModeData: if fine-grained fractional efficiency is required, consider modifying the underlying data structure to use a float or handle rounding explicitly. - This component operates directly on ECS component data (LeisureProviderData) via EntityManager and PrefabSystem; use it on the main thread where EntityManager operations are valid.