int[] array = new int[]
I can then access the array like a 3D array using:
int index = x * width * height + y * width + z;array[index]
The problem is that when I extend an array dimension (in this case the width) using the following set property:
width = value; // Create a temporary array using the new dimensions int[] tempArray = new int[depth * height * width]; if (width > oldWidth) { // Copy the current tiles to that array array.CopyTo(tempArray, 0); } else { for (int i = 0; i < tempArray.Length; ++i) { tempArray = array; } } array = tempArray;
the indices of the elements are no longer valid.
How can I adjust a dimension of the 1D array and assign the original elements so they can be accessed in the same way?