Skip to main content

CrZ_Array

CrZ_Array<T> is a static helper class for working with fixed-length arrays in place. Udon has no List<T>, so these methods let you search, fill, insert and remove elements on an array whose length never changes, using a caller-provided sentinel null value (for example -1 or "") to mark an empty slot instead of a real null.

Several methods (InsertValue, RemoveValue, RemoveValueByValue, Length) assume the array is kept packed from the left — every real value first, followed only by nullValue slots — and rely on that layout for their result to be meaningful.

If you need operations that actually grow or shrink the array, use CrZ_ResizableArray instead.

public static class CrZ_Array<T> where T : System.IComparable<T>

The type argument T must implement System.IComparable<T> (required by SortArrayAscending).


Methods​

InitializeArray​

Sets every slot of the array to the same value. Does nothing if array is null.

public static void InitializeArray(T[] array, T value)

Parameters:

ParameterTypeDescription
arrayT[]The array to fill.
valueTThe value written to every index.

Exists​

Returns whether the value is present in the array.

public static bool Exists(T[] array, T value)

Parameters:

ParameterTypeDescription
arrayT[]The array to search.
valueTThe value to look for.

Returns: true if the value is found; false if it is missing or array is null.


Index​

Returns the index of the first occurrence of the value.

public static int Index(T[] array, T value)

Parameters:

ParameterTypeDescription
arrayT[]The array to search.
valueTThe value to look for.

Returns: The zero-based index of the first match, or -1 if the value is missing or array is null.


Length​

Counts how many slots at the start of the array are filled, by scanning forward until it finds a slot equal to nullValue. Relies on the array being packed from the left (see the class notes above) — on a packed array this is the number of real entries, not the array's fixed capacity.

public static int Length(T[] array, T nullValue)

Parameters:

ParameterTypeDescription
arrayT[]The array to measure.
nullValueTThe sentinel that marks an empty slot.

Returns: The index of the first nullValue slot, or array.Length if every slot is filled. Returns 0 if array is null.


InsertValue​

Writes value into the first slot that currently holds nullValue. If there is no free slot, the array is left unchanged.

public static void InsertValue(T[] array, T value, T nullValue)

Parameters:

ParameterTypeDescription
arrayT[]The array to insert into.
valueTThe value to store.
nullValueTThe sentinel that marks an empty slot (for example "" or -1).

RemoveValueByValue​

Removes the first occurrence of valueToRemove. Every element after it is shifted one place to the left, and the last slot is set to nullValue. Does nothing if the value is not found.

public static void RemoveValueByValue(T[] array, T valueToRemove, T nullValue)

Parameters:

ParameterTypeDescription
arrayT[]The array to modify.
valueToRemoveTThe value to remove.
nullValueTThe sentinel written into the freed slot at the end.

RemoveValue​

Removes the element at pos. Every element after it is shifted one place to the left, and the last slot is set to nullValue. Does nothing if pos is out of range or array is null.

public static void RemoveValue(T[] array, int pos, T nullValue)

Parameters:

ParameterTypeDescription
arrayT[]The array to modify.
posintThe zero-based index of the element to remove.
nullValueTThe sentinel written into the freed slot at the end.

SortArrayAscending​

Sorts the array in ascending order, in place, using a selection sort and T.CompareTo. Does nothing if array is null.

public static void SortArrayAscending(T[] array)

Parameters:

ParameterTypeDescription
arrayT[]The array to sort.