Skip to content

Game.UI.IconValuePairs

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

Type: public class

Base: System.Object

Summary:
IconValuePairs is a simple utility class used to map numeric values to icon identifiers (strings) based on threshold stops. It holds an array of IconValuePair (a nested struct) where each pair defines an icon and a numeric "stop" threshold. Given a value, GetIconFromValue walks the array and returns the icon for the first pair whose stop is greater than or equal to the given value. If the array is null or empty, it returns an empty string. If the value is greater than all stops, it returns the icon from the last pair. For predictable results, the IconValuePair array should be ordered by stop (ascending).


Fields

  • private IconValuePair[] iconValuePairArray
    Holds the set of icon/threshold pairs that determine which icon to return for a given value. Expected to be ordered by stop ascending for correct range behavior. If null or empty, GetIconFromValue will return an empty string.

Nested types

  • public struct IconValuePair
  • public string icon { get; }
    The icon identifier (e.g., resource name or key) returned when the associated stop threshold matches.
  • public float stop { get; }
    The numeric threshold for this pair. Values less than or equal to this stop will match this pair (assuming iteration order).
  • public IconValuePair(string icon, float stop)
    Constructor to create a pair instance.

Properties

  • public string IconValuePair.icon { get; }
    Icon identifier accessor on the nested struct.

  • public float IconValuePair.stop { get; }
    Stop threshold accessor on the nested struct.

Constructors

  • public IconValuePairs(IconValuePair[] iconValuePairArray)
    Creates a new IconValuePairs instance using the provided array of IconValuePair. The array is stored as-is; no defensive copy is made.

  • public IconValuePair(string icon, float stop) (nested struct constructor)
    Creates a new IconValuePair with the given icon string and stop value.

Methods

  • public string GetIconFromValue(float value)
    Returns the icon corresponding to the provided value by iterating the iconValuePairArray in order:
  • If iconValuePairArray is null or empty -> returns string.Empty.
  • Iterates the array and returns the icon of the first pair where value <= pair.stop.
  • If no pair matched (value is greater than all stops) -> returns the icon of the last pair in the array. Notes:
  • Iteration is linear (O(n)).
  • The code uses C# index-from-end (iconValuePairArray[^1]) to access the last element.
  • For correct mapping of ranges, supply the array sorted by stop in ascending order.

Usage Example

// Define the mapping (stops should be in ascending order)
var pairs = new IconValuePairs.IconValuePair[]
{
    new IconValuePairs.IconValuePair("icon_low", 25f),
    new IconValuePairs.IconValuePair("icon_medium", 50f),
    new IconValuePairs.IconValuePair("icon_high", 75f),
    new IconValuePairs.IconValuePair("icon_max", 100f),
};

// Create the helper
var iconMap = new IconValuePairs(pairs);

// Query for a value
float value = 60f;
string icon = iconMap.GetIconFromValue(value); // returns "icon_high"