Game.Prefabs.Modes.ElectricityParametersMode
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs.Modes
Type: class
Base: EntityQueryModePrefab
Summary:
A Mode prefab that exposes global electricity-related parameters to the ECS world. This prefab maps inspector-configurable fields (initial battery charge, temperature consumption multiplier curve, and cloudiness solar penalty) into the ElectricityParameterData component on the singleton entity used by the electricity systems. It is marked with a ComponentMenu attribute so it can be created/edited as a mode prefab in the editor.
Fields
-
public float m_InitialBatteryCharge
Initial state-of-charge applied to batteries (0.0–1.0). Decorated with [Range(0f, 1f)] to constrain values in the inspector. When ApplyModeData runs this value is written into ElectricityParameterData.m_InitialBatteryCharge. -
public AnimationCurve m_TemperatureConsumptionMultiplier
An animation curve that defines a multiplier applied to consumption as a function of temperature. This is converted to an AnimationCurve1 wrapper when writing to the ECS component (AnimationCurve1 is the serializable/ECS-friendly representation used by the component). -
public float m_CloudinessSolarPenalty
Fractional penalty applied to solar generation due to cloudiness (0.0–1.0). Also decorated with [Range(0f, 1f)]. Written into ElectricityParameterData.m_CloudinessSolarPenalty.
Properties
- None declared on this type. (All interaction is via public fields and overridden methods.)
Constructors
public ElectricityParametersMode()
Default parameterless constructor (implicit). No custom construction logic is defined in the class.
Methods
-
public override EntityQueryDesc GetEntityQueryDesc()
Returns an EntityQueryDesc that targets the ElectricityParameterData singleton (All = ComponentType.ReadOnly()). Used by the mode system to find the singleton entity to apply changes to. -
protected override void RecordChanges(EntityManager entityManager, Entity entity)
Reads the ElectricityParameterData component from the given entity. This method is used to record the original state before changes (the read call ensures the system tracks that component for change recording). -
public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
Writes the current prefab field values into the ElectricityParameterData component on the singleton entity returned by requestedQuery.GetSingletonEntity(). Specifically: - m_InitialBatteryCharge -> ElectricityParameterData.m_InitialBatteryCharge
- m_TemperatureConsumptionMultiplier -> ElectricityParameterData.m_TemperatureConsumptionMultiplier (wrapped to AnimationCurve1)
-
m_CloudinessSolarPenalty -> ElectricityParameterData.m_CloudinessSolarPenalty
Returns the received JobHandle (no new jobs are scheduled here). -
public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
Restores the component data for the first entity in the provided entities array using values from the corresponding ElectricityParametersPrefab obtained from the PrefabSystem. This is used when resetting mode data to the prefab defaults.
Notes: - The class uses AnimationCurve1 as the component-friendly representation of UnityEngine.AnimationCurve when writing to the ECS component. - The Apply/Restore methods perform a GetComponentData / SetComponentData sequence on the EntityManager; they expect the target entity to already have an ElectricityParameterData component.
Usage Example
// Example: update mode prefab values and apply them to the ECS singleton.
// Typically this prefab is edited in the editor; shown here is how to apply programmatically.
ElectricityParametersMode modePrefab = /* obtain reference to the prefab instance */;
modePrefab.m_InitialBatteryCharge = 0.2f;
modePrefab.m_CloudinessSolarPenalty = 0.3f;
modePrefab.m_TemperatureConsumptionMultiplier = new AnimationCurve(
new Keyframe(-10f, 1.5f),
new Keyframe(0f, 1f),
new Keyframe(30f, 0.9f)
);
// When the mode system calls ApplyModeData it will propagate these values into
// the ElectricityParameterData singleton component. If calling manually:
EntityQuery query = world.EntityManager.CreateEntityQuery(typeof(ElectricityParameterData));
modePrefab.ApplyModeData(world.EntityManager, query, default);