Skip to content

Game.Prefabs.Modes.ServiceFeeParameterMode

Assembly: Game
Namespace: Game.Prefabs.Modes

Type: class

Base: EntityQueryModePrefab

Summary:
ServiceFeeParameterMode is a mode prefab used to configure service fee-related parameters (electricity, water, healthcare, education, garbage, fire response, police, etc.) and apply them to the runtime ECS component ServiceFeeParameterData. The prefab holds editable Unity types (FeeParameters, AnimationCurve, int4) that are copied into the singleton ServiceFeeParameterData when the mode is applied, and can also restore values from the original ServiceFeeParameterPrefab.


Fields

  • public FeeParameters m_ElectricityFee
    Fee parameter structure used for electricity pricing. Copied into ServiceFeeParameterData.m_ElectricityFee when ApplyModeData or RestoreDefaultData runs.

  • public AnimationCurve m_ElectricityFeeConsumptionMultiplier
    Unity AnimationCurve used in editor to define how electricity consumption scales with fee. When applied to ECS component it is converted to an AnimationCurve1 and stored in ServiceFeeParameterData.m_ElectricityFeeConsumptionMultiplier.

  • public FeeParameters m_HealthcareFee
    Fee parameters for healthcare services. Copied into ServiceFeeParameterData.m_HealthcareFee.

  • public FeeParameters m_BasicEducationFee
    Fee parameters for basic education. Copied into ServiceFeeParameterData.m_BasicEducationFee.

  • public FeeParameters m_SecondaryEducationFee
    Fee parameters for secondary education. Copied into ServiceFeeParameterData.m_SecondaryEducationFee.

  • public FeeParameters m_HigherEducationFee
    Fee parameters for higher education. Copied into ServiceFeeParameterData.m_HigherEducationFee.

  • public FeeParameters m_WaterFee
    Fee parameter structure used for water pricing. Copied into ServiceFeeParameterData.m_WaterFee.

  • public AnimationCurve m_WaterFeeConsumptionMultiplier
    Unity AnimationCurve for water consumption multiplier; converted to AnimationCurve1 and stored in ServiceFeeParameterData.m_WaterFeeConsumptionMultiplier.

  • public FeeParameters m_GarbageFee
    Fee parameters for garbage collection service. Copied into ServiceFeeParameterData.m_GarbageFee.

  • public int4 m_GarbageFeeRCIO
    int4 vector representing per-R/C/I/O (Residential / Commercial / Industrial / Office) garbage fee values or weights. Copied into ServiceFeeParameterData.m_GarbageFeeRCIO.

  • public FeeParameters m_FireResponseFee
    Fee parameters for fire response service. Copied into ServiceFeeParameterData.m_FireResponseFee.

  • public FeeParameters m_PoliceFee
    Fee parameters for police service. Copied into ServiceFeeParameterData.m_PoliceFee.

Properties

  • This class declares no public properties.

Constructors

  • public ServiceFeeParameterMode()
    The class does not declare an explicit constructor; the default parameterless constructor is used. Instances are typically created by the game/prefab system (it is a prefab component with ComponentMenu attribute), and values are usually set in the Unity editor.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that matches entities containing the ServiceFeeParameterData component. Implementation:
  • Creates a new EntityQueryDesc with All = [ComponentType.ReadOnly()].
  • Used by the system to find the singleton entity that holds service fee parameters.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Reads the ServiceFeeParameterData component from the given entity (via entityManager.GetComponentData) to mark/record the component for change tracking. This method does not modify data; it's used by whatever mode management system expects RecordChanges to access the component.

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Applies the prefab values stored in this ServiceFeeParameterMode instance to the runtime ECS singleton:

  • Obtains the singleton entity with requestedQuery.GetSingletonEntity().
  • Reads ServiceFeeParameterData from that entity.
  • Copies each corresponding field from this prefab instance into the component data:
    • Copies FeeParameters fields (electricity, healthcare, education, water, garbage, fire, police).
    • Converts AnimationCurve fields into AnimationCurve1 (AnimationCurve1 is the ECS-friendly representation used in the component).
    • Copies m_GarbageFeeRCIO (int4).
  • Calls entityManager.SetComponentData(singletonEntity, componentData) to write back.
  • Returns the incoming JobHandle deps unchanged (operation is synchronous on main thread).

Notes: - This method uses EntityManager.SetComponentData and AnimationCurve1 conversion; it runs on the main thread and is not scheduled as a job.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Restores values from the original ServiceFeeParameterPrefab stored in the PrefabSystem for the provided entity:
  • Gets the first entity in entities (entities[0]) and the associated ServiceFeeParameterPrefab via prefabSystem.GetPrefab(entity).
  • Reads the current ServiceFeeParameterData for the entity, then overwrites fields with values from the prefab:
    • Copies FeeParameters and int4.
    • Converts AnimationCurve fields from the prefab into AnimationCurve1.
  • Writes the updated component back with entityManager.SetComponentData(entity, componentData).

Use this to revert runtime tweaks back to the original prefab defaults.

Usage Example

// Example showing how the mode might be applied programmatically.
// In-game the mode system handles instances of ServiceFeeParameterMode automatically,
// but you can invoke ApplyModeData manually if needed.

ServiceFeeParameterMode mode = /* obtain prefab instance from PrefabSystem or inspector */;
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var query = entityManager.CreateEntityQuery(ComponentType.ReadOnly<ServiceFeeParameterData>());

// Apply the mode values to the singleton component (runs on main thread)
mode.ApplyModeData(entityManager, query, default);

// To restore defaults from the original ServiceFeeParameterPrefab:
var prefabSystem = /* get PrefabSystem from game context */;
NativeArray<Entity> entities = /* an array containing the entity to restore */;
mode.RestoreDefaultData(entityManager, ref entities, prefabSystem);

Notes and tips: - The prefab stores Unity editor types (AnimationCurve) but the running ECS component uses AnimationCurve1. The conversion is handled in ApplyModeData and RestoreDefaultData. - This class is intended for configuration in the editor. Avoid calling ApplyModeData from worker jobs — it uses EntityManager.SetComponentData and should run on the main thread. - m_GarbageFeeRCIO is an int4; its components usually correspond to Residential, Commercial, Industrial, Office categories used by the game. Adjust accordingly in editor.