Game.UI.InGame.ModifierUIUtils
Assembly:
Assembly-CSharp
Namespace:
Game.UI.InGame
Type:
public static class
Base:
System.Object
Summary:
Utility helpers for converting and formatting modifier values for UI presentation. Provides conversion of raw modifier delta values into display-friendly values depending on the modifier's value mode (e.g., relative percentages vs. absolute values) and returns the UI unit key to use when rendering the value (e.g., percentage vs. float fraction). The methods are pure, stateless, and safe to call from UI code.
Fields
- None
No instance or static fields are declared in this utility class.
Properties
- None
This static utility class exposes only methods.
Constructors
- None
Static classes have no public constructors.
Methods
public static float GetModifierDelta(ModifierValueMode mode, float delta)
Converts a raw modifier delta into a value suitable for display depending on the provided ModifierValueMode.
Behavior: - ModifierValueMode.Relative: returns 100f * delta — converts a relative fraction (e.g., 0.05) into a percentage (5). - ModifierValueMode.InverseRelative: returns 100f * (1f / math.max(0.001f, 1f + delta) - 1f) — computes the inverse relative change expressed as a percentage. Uses math.max to clamp the denominator to at least 0.001f to avoid division by zero or extremely small denominators. - Other modes (including ModifierValueMode.Absolute): returns delta unchanged.
Notes: - The InverseRelative branch is intended for situations where you want to show the change from the perspective of applying an inverse multiplier (e.g., displaying how much a value would change when dividing by (1 + delta)). Be aware that values of delta near -1 can produce very large results due to the clamp; this is deliberate to avoid division by zero but can lead to large displayed numbers. - Uses Unity.Mathematics.math.max for the clamp.
public static string GetModifierUnit(ModifierValueMode mode)
Returns a UI unit key (string) indicating how the modifier should be labeled in the UI.- If mode == ModifierValueMode.Absolute: returns "floatSingleFraction" (indicates a raw float fraction unit).
- Otherwise: returns "percentage" (indicates a percentage unit used for relative/inverse-relative values).
Notes: - The returned strings appear to be keys/identifiers used by the UI/localization system to select the correct unit label or formatting rule. They are not formatted user-facing strings by themselves.
Usage Example
// Example usages of ModifierUIUtils
using Game.UI.InGame;
using Game.Prefabs;
// Relative example: fraction -> percent
float rawDelta = 0.05f;
float displayValue = ModifierUIUtils.GetModifierDelta(ModifierValueMode.Relative, rawDelta); // 5.0
string unitKey = ModifierUIUtils.GetModifierUnit(ModifierValueMode.Relative); // "percentage"
// Absolute example: value left unchanged, unit indicates fraction
float absDelta = 0.25f;
float absDisplay = ModifierUIUtils.GetModifierDelta(ModifierValueMode.Absolute, absDelta); // 0.25
string absUnit = ModifierUIUtils.GetModifierUnit(ModifierValueMode.Absolute); // "floatSingleFraction"
// Inverse relative example: shows inverse change as percent
float invDelta = -0.5f;
float invDisplay = ModifierUIUtils.GetModifierDelta(ModifierValueMode.InverseRelative, invDelta); // 100.0
string invUnit = ModifierUIUtils.GetModifierUnit(ModifierValueMode.InverseRelative); // "percentage"
Additional implementation notes: - The class depends on: - Game.Prefabs.ModifierValueMode enum (expected values include Relative, InverseRelative, Absolute). - Unity.Mathematics.math for the max clamp. - The methods are thread-safe and allocate no managed memory; they are suitable for frequent calls from UI update code.