Struct IntRange
Represents an inclusive minimum/maximum range of 32-bit signed integer values. Useful for designer-authored data such as enemy spawn level ranges, randomized loot quantities, difficulty tier bounds, and any other parameter where a whole-number value must fall between two bounds.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Ranges
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public struct IntRange : IEquatable<IntRange>
Remarks
IntRange is a value type (struct) and is fully serializable
by Unity's Inspector via [Serializable] and [SerializeField]. It can
be used as a Unity Inspector field directly, and a custom UI Toolkit drawer renders
a min/max two-field row by default.
The range is inclusive on both ends. Random() compensates for the
exclusive upper bound of Range(int, int) by
passing Max + 1, so Max is a possible result. The constructor
performs no ordering check; callers responsible for the invariant Min <= Max
must validate the inputs explicitly. Use IsEmpty and
IsValid to inspect the configured bounds.
Equality uses exact integer comparison; no approximation is applied.
Constructors
IntRange(int, int)
Initializes a new IntRange with the supplied min
and max bounds. The constructor performs no ordering check.
Declaration
public IntRange(int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | min | The lower bound (inclusive). |
| int | max | The upper bound (inclusive). |
Fields
Zero
Declaration
public static readonly IntRange Zero
Field Value
| Type | Description |
|---|---|
| IntRange |
ZeroToTen
An IntRange spanning 0 to 10, inclusive. Common for
small bounded parameters such as level brackets and stack counts.
Declaration
public static readonly IntRange ZeroToTen
Field Value
| Type | Description |
|---|---|
| IntRange |
Properties
Count
The number of distinct integer values contained in this range, computed as
Max - Min + 1. Returns 0 when the range is invalid.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsValid
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Max
The upper bound of this range (inclusive).
Declaration
public int Max { get; }
Property Value
| Type | Description |
|---|---|
| int |
Min
The lower bound of this range (inclusive).
Declaration
public int Min { get; }
Property Value
| Type | Description |
|---|---|
| int |
Size
The size of the range, equal to Max minus Min. May be negative when the range is invalid (Min > Max).
Declaration
public int Size { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Clamp(int)
Clamps value to the inclusive bounds of this range using
Clamp(int, int, int).
Declaration
public int Clamp(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to clamp. |
Returns
| Type | Description |
|---|---|
| int | The clamped value. |
Contains(int)
Returns true when value is within the inclusive bounds
of this range.
Declaration
public bool Contains(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to test. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(IntRange)
Determines whether two IntRange values are exactly equal by comparing both Min and Max via integer equality.
Declaration
public bool Equals(IntRange other)
Parameters
| Type | Name | Description |
|---|---|---|
| IntRange | other | The other range to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Determines whether the specified object is an IntRange equal to this instance.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer hash code. |
Overrides
Random()
Returns a uniformly distributed random value drawn from this range, inclusive on
both ends. Internally calls Range(int, int) with
Max + 1 to compensate for that overload's exclusive upper bound.
Declaration
public int Random()
Returns
| Type | Description |
|---|---|
| int |
ToString()
Returns a human-readable string representation of this range using the invariant culture for number formatting.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format |
Overrides
Operators
operator ==(IntRange, IntRange)
Returns true when both operands have equal bounds.
Declaration
public static bool operator ==(IntRange left, IntRange right)
Parameters
| Type | Name | Description |
|---|---|---|
| IntRange | left | The left-hand operand. |
| IntRange | right | The right-hand operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(IntRange, IntRange)
Returns true when the operands differ in either bound.
Declaration
public static bool operator !=(IntRange left, IntRange right)
Parameters
| Type | Name | Description |
|---|---|---|
| IntRange | left | The left-hand operand. |
| IntRange | right | The right-hand operand. |
Returns
| Type | Description |
|---|---|
| bool |
|