Class FlatArrayIndex
This extension class contains methods for interacting with a flat array as though it were a three dimensional array.
Unity-serializable arrays can only be 1 dimensional - this class allows the user to interact with them in a 3D context.
Inheritance
Inherited Members
Namespace: CarbideFunction.Wildtile
Syntax
public static class FlatArrayIndex
Methods
GetFlatArraySize(Vector3Int)
Calculate the size of the flat array that would match the number of elements in a 3D grid of size dimensions
Declaration
public static int GetFlatArraySize(this Vector3Int dimensions)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | dimensions |
Returns
Type | Description |
---|---|
System.Int32 |
To3dCoordinate(Int32, Vector3Int)
Convert a 1D flat array index into a 3D coordinate given the grid dimensions.
This assumes the flat array index is within the dimensions, no checks are made. The result is undefined if the flat index is not in the range [0- dimensions.x * y * z).
Declaration
public static Vector3Int To3dCoordinate(this int index, Vector3Int dimensions)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
Vector3Int | dimensions |
Returns
Type | Description |
---|---|
Vector3Int |
ToFlatArrayIndex(Vector3Int, Vector3Int)
Convert a 3D coordinate into a flat array index given the grid dimensions
Declaration
public static int ToFlatArrayIndex(this Vector3Int coordinate, Vector3Int dimensions)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | coordinate | The 3D coordinates of the query point. All components must be less than their corresponding |
Vector3Int | dimensions | The 3D dimensions of the grid |
Returns
Type | Description |
---|---|
System.Int32 |