Skip to content

Game.UI.Widgets.RangeNAttribute

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

Type: class

Base: UnityEngine.PropertyAttribute

Summary:
Attribute used to specify per-component minimum and maximum ranges for N-dimensional numeric values (using Unity.Mathematics float2/float3/float4). The attribute stores min and max as float4 values and provides multiple overloads to construct those float4 ranges from scalar, float2, float3, or float4 inputs. Intended for use by the game's UI/editor/widget code to drive range sliders/validation for vector-like properties.


Fields

  • This class defines no explicit (source-level) fields. It exposes two auto-implemented properties (backed by compiler-generated fields) for the range values.

Properties

  • public Unity.Mathematics.float4 min { get; private set; }
    The minimum value for each component of the range. Internally stored as a float4. The different constructors populate this float4 differently:
  • From a single float with componentExpansion = true: all components set to that scalar.
  • From a single float with componentExpansion = false: x set to the scalar, y/z/w set to 0.
  • From float2: x,y set from the float2; z,w = 0.
  • From float3: x,y,z set from the float3; w = 0.
  • From float4: assigned directly.

  • public Unity.Mathematics.float4 max { get; private set; }
    The maximum value for each component of the range. Same population rules as min (mirrors the corresponding constructor logic).

Constructors

  • public RangeNAttribute(float min, float max, bool componentExpansion = true)
    Creates a range where min/max are provided as scalars. If componentExpansion is true (default), the scalar is expanded to all four components (float4(min)). If componentExpansion is false, the scalar is used for the x component and the other components are set to zero (float4(min, 0, 0, 0)). Useful when you want a uniform range across all components or only for the first component.

  • public RangeNAttribute(float2 min, float2 max)
    Creates a range using float2 for x and y components; z and w are set to zero (new float4(min, float2.zero)). Note: float2 is a Unity.Mathematics type.

  • public RangeNAttribute(float3 min, float3 max)
    Creates a range using float3 for x,y,z components; w is set to zero (new float4(min, 0f)).

  • public RangeNAttribute(float4 min, float4 max)
    Creates a range using full float4 min and max values (assigned directly).

Methods

  • This class declares no additional methods beyond the constructors and the auto-implemented property accessors.

Notes / Remarks

  • The attribute stores ranges as Unity.Mathematics.float4. The presence of float2/float3/float4 overloads allows convenient construction from different vector sizes.
  • Be aware that C# attribute arguments are normally required to be compile-time constant expressions of certain primitive types; passing struct instances (like float2/float3/float4) directly in attribute usage in regular source code may not be allowed by the C# language/compiler. In typical usage in user code, prefer the scalar overload (float min, float max). The game/editor code may create and use instances of this attribute via reflection or other runtime means where non-constant constructors are used.
  • This attribute is a UI/editor helper: its runtime effect depends on the inspector/property drawer or widget code that reads it. Unity's default inspector does not automatically support float4 sliders; custom UI code in the game likely consumes this attribute.

Usage Example

using Unity.Mathematics;
using Game.UI.Widgets;

// Uniform range applied to all components (0..1)
[RangeN(0f, 1f)]
public float4 myVectorRange;

// Only the X component has the scalar range, others default to 0
[RangeN(0f, 10f, componentExpansion: false)]
public float4 onlyXRange;

// If the game's UI/editor constructs attributes at runtime, you might also see:
// var attr = new RangeNAttribute(new float2(0f, 0f), new float2(10f, 10f));