Skip to content

Game.UI.Widgets.WidgetAttributeUtils

Assembly: Game
Namespace: Game.UI.Widgets

Type: static class

Base: System.Object

Summary:
Utility helper for inspecting attribute arrays (object[]), used by UI widget code to adapt field rendering and behavior based on decorating attributes. Provides checks for common widget-related attributes (e.g., InputFieldAttribute, TimeFieldAttribute), helpers to read color usage, numeric ranges and steps, units and custom field factories. Designed to be invoked with the attribute array returned by reflection (e.g., MemberInfo.GetCustomAttributes(true) or similar) when building or configuring UI fields in mod code for Cities: Skylines 2.


Fields

  • This static class declares no fields.
    This type exposes only static methods — there are no instance or backing fields to document.

Properties

  • This static class declares no properties.
    All functionality is provided through static methods.

Constructors

  • This static class has no public constructors.
    As a static class it cannot be instantiated; any runtime initialization would be in a static constructor if present (none declared here).

Methods

  • public static bool RequiresInputField(object[] attributes) : System.Boolean
    Returns true if the attributes contain an InputFieldAttribute. Use this to detect that the UI should render an input-style text field rather than a simple label/editor control.

  • public static bool IsTimeField(object[] attributes) : System.Boolean
    Returns true if the attributes contain a TimeFieldAttribute. Useful to render/validate time-specific input controls.

  • public static bool AllowsMinGreaterMax(object[] attributes) : System.Boolean
    Returns true if the attributes contain an AllowMinGreaterMaxAttribute. Indicates whether min > max is allowed for numeric ranges (some UI may clamp or swap otherwise).

  • public static void GetColorUsage(object[] attributes, ref bool hdr, ref bool showAlpha) : System.Void
    Reads a UnityEngine.ColorUsageAttribute (if present) and sets the provided hdr and showAlpha ref parameters accordingly. If no ColorUsageAttribute is present, the ref values are left unchanged.

  • public static bool GetNumberRange(object[] attributes, ref int min, ref int max) : System.Boolean
    Checks for RangeAttribute or RangeNAttribute and, if found, fills min/max with integer range values and returns true. RangeNAttribute contains float4 vectors; for scalar overloads the X component is used.

  • public static bool GetNumberRange(object[] attributes, ref uint min, ref uint max) : System.Boolean
    Same as the int overload but writes values as unsigned integers (casts are performed).

  • public static bool GetNumberRange(object[] attributes, ref float min, ref float max) : System.Boolean
    Reads RangeAttribute or RangeNAttribute and fills float min/max values. Returns true when a range attribute is found.

  • public static bool GetNumberRange(object[] attributes, ref float4 min, ref float4 max) : System.Boolean
    Reads a RangeAttribute or RangeNAttribute and fills float4 min/max vectors. This overload directly preserves vector ranges provided by RangeNAttribute (or RangeAttribute if it exposes vector values).

  • public static bool GetNumberRange(object[] attributes, ref double min, ref double max) : System.Boolean
    Reads range info and fills double min/max (casts from attribute values when necessary).

  • public static int GetNumberStep(object[] attributes, int defaultStep = 1) : System.Int32
    Returns the integer step from a NumberStepAttribute if present and valid (> 0); otherwise returns defaultStep.

  • public static uint GetNumberStep(object[] attributes, uint defaultStep = 1u) : System.UInt32
    Returns the unsigned integer step from a NumberStepAttribute if present and valid (!= 0); otherwise returns defaultStep.

  • public static float GetNumberStep(object[] attributes, float defaultStep = 0.01f) : System.Single
    Returns the float step from a NumberStepAttribute if present and > 0; otherwise returns defaultStep.

  • public static double GetNumberStep(object[] attributes, double defaultStep = 0.01) : System.Double
    Returns the double step from a NumberStepAttribute if present and > 0; otherwise returns defaultStep.

  • [CanBeNull] public static string GetNumberUnit(object[] attributes) : System.String
    Returns the Unit string from a NumberUnitAttribute if present; otherwise returns null. Useful to display units (e.g., "m", "km/h") next to numeric fields.

  • public static Type GetCustomFieldFactory(object[] attributes) : System.Type
    Returns the Factory type from a CustomFieldAttribute if present; otherwise returns null. Used to create or supply custom field implementations for complex or custom-drawn properties.

Usage Example

// Example: inspecting attributes retrieved via reflection for a property/field
object[] attributes = memberInfo.GetCustomAttributes(true);

if (WidgetAttributeUtils.RequiresInputField(attributes))
{
    // render an input text field
}

bool hdr = false, showAlpha = true;
WidgetAttributeUtils.GetColorUsage(attributes, ref hdr, ref showAlpha);
// hdr/showAlpha now reflect ColorUsageAttribute if present

int min = 0, max = 100;
if (WidgetAttributeUtils.GetNumberRange(attributes, ref min, ref max))
{
    // use min/max to configure an integer slider
}

float step = WidgetAttributeUtils.GetNumberStep(attributes, 0.5f);
string unit = WidgetAttributeUtils.GetNumberUnit(attributes);
Type customFactory = WidgetAttributeUtils.GetCustomFieldFactory(attributes);