Game.ElectricityInfoviewUISystem
Assembly: (inferred: Game)
Namespace: Game.UI.InGame
Type: class
Base: InfoviewUISystemBase
Summary:
Provides the in-game electricity infoview UI bindings. The system connects to ElectricityStatisticsSystem and ElectricityTradeSystem, creates GetterValueBinding instances for multiple electricity-related values (production, consumption, transmission, trade, battery charge, etc.), updates those bindings each frame, and exposes indicator values that the UI can render. It also queries outside-trade parameters for calculating trade indicators.
Fields
-
private ElectricityStatisticsSystem m_ElectricityStatisticsSystem
Holds a reference to the ElectricityStatisticsSystem used to read production, consumption, fulfilled consumption, battery capacity/charge and other electricity-related stats. -
private ElectricityTradeSystem m_ElectricityTradeSystem
Holds a reference to the ElectricityTradeSystem used to read import/export amounts for electricity trade. -
private EntityQuery m_OutsideTradeParameterGroup
EntityQuery used to check for and read the singleton OutsideTradeParameterData to obtain export/import prices for trade calculations. -
private GetterValueBinding<int> m_ElectricityProduction
Getter binding for the integer electricity production value (group "electricityInfo", key "electricityProduction"). Reads from m_ElectricityStatisticsSystem.production. -
private GetterValueBinding<int> m_ElectricityConsumption
Getter binding for the integer electricity consumption value (group "electricityInfo", key "electricityConsumption"). Reads from m_ElectricityStatisticsSystem.consumption. -
private GetterValueBinding<int> m_ElectricityTransmitted
Getter binding for the integer fulfilled/transmitted electricity (group "electricityInfo", key "electricityTransmitted"). Reads from m_ElectricityStatisticsSystem.fulfilledConsumption. -
private GetterValueBinding<int> m_ElectricityExport
Getter binding for electricity export amount (group "electricityInfo", key "electricityExport"). Reads from m_ElectricityTradeSystem.export. -
private GetterValueBinding<int> m_ElectricityImport
Getter binding for electricity import amount (group "electricityInfo", key "electricityImport"). Reads from m_ElectricityTradeSystem.import. -
private GetterValueBinding<IndicatorValue> m_ElectricityAvailability
Getter binding that supplies an IndicatorValue representing production vs consumption (group "electricityInfo", key "electricityAvailability"). Uses GetElectricityAvailability. -
private GetterValueBinding<IndicatorValue> m_ElectricityTransmission
Getter binding that supplies an IndicatorValue representing transmission fulfillment (group "electricityInfo", key "electricityTransmission"). Uses GetElectricityTransmission. -
private GetterValueBinding<IndicatorValue> m_ElectricityTrade
Getter binding that supplies an IndicatorValue for trade balance based on import/export and outside prices (group "electricityInfo", key "electricityTrade"). Uses GetElectricityTrade. -
private GetterValueBinding<IndicatorValue> m_BatteryCharge
Getter binding that supplies an IndicatorValue representing battery charge relative to capacity (group "electricityInfo", key "batteryCharge"). Uses GetBatteryCharge.
Properties
protected override bool Active { get; }
Determines whether this UI system is active. Returns true if the base.Active is true or if any of the binding fields are active. The check tests all main bindings (production, consumption, transmitted, export, import, availability, transmission, trade) and finally battery charge; if none are active and base.Active is false, this property returns false.
Constructors
public ElectricityInfoviewUISystem()
Default constructor. The system has a [Preserve] attribute in code, but otherwise no custom initialization is performed in the constructor; initialization happens in OnCreate.
Methods
-
protected override void OnCreate()
Initializes the system: calls base.OnCreate(), obtains managed system references via World.GetOrCreateSystemManaged for ElectricityStatisticsSystem and ElectricityTradeSystem, creates an EntityQuery for OutsideTradeParameterData, and registers all GetterValueBinding instances with AddBinding. Each binding is configured with the group "electricityInfo" and an appropriate key name. Bindings for IndicatorValue use ValueWriter. -
protected override void PerformUpdate()
Called each update to refresh UI values. Calls Update() on every GetterValueBinding so the UI receives the latest values. -
private IndicatorValue GetElectricityTransmission()
Builds and returns an IndicatorValue with: - min = 0
- max = m_ElectricityStatisticsSystem.consumption
-
current = m_ElectricityStatisticsSystem.fulfilledConsumption Represents how much of consumption is currently fulfilled (transmitted).
-
private IndicatorValue GetElectricityAvailability()
Returns IndicatorValue.Calculate(production, consumption) using values from m_ElectricityStatisticsSystem. Represents availability of electricity relative to demand. -
private IndicatorValue GetElectricityTrade()
If an OutsideTradeParameterData singleton exists, calculates a normalized trade indicator: - Computes trade balance in currency: export * exportPrice - import * importPrice
- Normalizes by a positive baseline = max(0.01, consumption * exportPrice)
-
Clamps result to [-1, 1] and returns new IndicatorValue(-1, 1, clampedValue) If no outside-trade parameters exist, returns IndicatorValue(-1, 1, 0). Uses Unity.Mathematics.math.clamp and math.max.
-
private IndicatorValue GetBatteryCharge()
Returns new IndicatorValue(0, batteryCapacity, batteryCharge) from m_ElectricityStatisticsSystem.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Obtain referenced systems
m_ElectricityStatisticsSystem = World.GetOrCreateSystemManaged<ElectricityStatisticsSystem>();
m_ElectricityTradeSystem = World.GetOrCreateSystemManaged<ElectricityTradeSystem>();
// Query outside trade parameters
m_OutsideTradeParameterGroup = GetEntityQuery(ComponentType.ReadOnly<OutsideTradeParameterData>());
// Register bindings (group "electricityInfo", keys as shown)
AddBinding(m_ElectricityProduction = new GetterValueBinding<int>("electricityInfo", "electricityProduction", () => m_ElectricityStatisticsSystem.production));
AddBinding(m_ElectricityConsumption = new GetterValueBinding<int>("electricityInfo", "electricityConsumption", () => m_ElectricityStatisticsSystem.consumption));
// ...other bindings similarly registered (transmitted, export, import, availability, transmission, trade, batteryCharge)
}
Notes and remarks: - This system assumes ElectricityStatisticsSystem and ElectricityTradeSystem are present/registered in the same World and exposes the necessary properties used here (production, consumption, fulfilledConsumption, batteryCapacity, batteryCharge, export, import). - IndicatorValue is used to convey min/max/current triples (or ranged indicator values) the UI can render. - OutsideTradeParameterData is read as a singleton to obtain export/import prices for trade normalization; the system handles absence of that singleton by returning a neutral trade indicator.