Skip to content

Game.UI.InGame.PollutionUIUtils

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: public static class PollutionUIUtils

Base: static class (no instance base)

Summary:
Utility helper for mapping a raw pollution value to a PollutionThreshold enum value using a set of configured thresholds (low, medium, high). Designed for UI code that needs to classify pollution into discrete buckets for display or logic (e.g., color, icons, or messages). The method is stateless and thread-safe.


Fields

  • This class defines no instance or static fields. It is a stateless static utility class.

Properties

  • This class defines no properties.

Constructors

  • This static class has no public constructors and cannot be instantiated. No explicit static constructor is defined.

Methods

  • public static PollutionThreshold GetPollutionKey(UIPollutionThresholds data, float pollution)
    Maps the provided pollution value to a PollutionThreshold based on the thresholds contained in the provided UIPollutionThresholds object.

Behavior details: - Compares the float pollution value to the thresholds in the following order: 1. If pollution > data.m_High -> returns PollutionThreshold.High 2. Else if pollution > data.m_Medium -> returns PollutionThreshold.Medium 3. Else if pollution > data.m_Low -> returns PollutionThreshold.Low 4. Otherwise -> returns PollutionThreshold.None - Note that comparisons use a strict greater-than (>) operator. That means a pollution value equal to a threshold is treated as belonging to the next lower bucket (e.g., pollution == m_Medium will be classified as Low, not Medium). - The code casts threshold fields to float when comparing (float)data.m_High etc.), which implies the threshold fields are numeric but not necessarily float (commonly int/byte/short). The cast ensures the comparison is performed in float precision. - The method requires a non-null UIPollutionThresholds reference; the method does not perform null checks — callers should ensure data is not null to avoid a NullReferenceException.

Parameters: - data: UIPollutionThresholds — object containing the threshold values used for classification (fields referenced: m_Low, m_Medium, m_High). - pollution: float — the pollution value to classify.

Return: - PollutionThreshold — enum value representing the bucket (None, Low, Medium, High).

Usage Example

// Assume UIPollutionThresholds and PollutionThreshold are available in scope.
// Example usage in UI code:

UIPollutionThresholds thresholds = new UIPollutionThresholds {
    m_Low = 10,    // example values (int/byte/etc.)
    m_Medium = 30,
    m_High = 60
};

float currentPollution = 35.0f;

PollutionThreshold key = PollutionUIUtils.GetPollutionKey(thresholds, currentPollution);
// key == PollutionThreshold.Medium

// Note: equality uses strict > comparisons:
// if currentPollution == 30.0f, result would be PollutionThreshold.Low (since 30 > 30 is false).

{{ Additional notes: - Because this class is a trivial stateless helper, it can be used freely from UI update code without lifecycle management. - If you need inclusive thresholds (>=) adjust the comparison operators accordingly. - Validate or sanitize the UIPollutionThresholds values upstream if you need specific guarantees (e.g., m_Low <= m_Medium <= m_High). }}