Last active
December 21, 2022 19:27
-
-
Save Sin-Gala/f98571a2f7530179e1ade8d4e854e3ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public T[] ConvertMultiArrayToSingleArray(T[,] multiArray) | |
{ | |
int x = multiArray.GetLength(0); | |
int y = multiArray.GetLength(1); | |
T[] singleArray = new T[x * y]; | |
int index = 0; | |
for (int i = 0; i < x; i++) | |
{ | |
for (int j = 0; j < y; j++) | |
{ | |
singleArray[index++] = multiArray[i, j]; | |
} | |
} | |
return singleArray; | |
} | |
public T[,] ConvertSingleArrayToMultiArray(T[] singleArray, Vector2Int size) | |
{ | |
T[,] multiArray = new T[size.x, size.y]; | |
int index = 0; | |
for (int i = 0; i < size.x; i++) | |
{ | |
for (int j = 0; j < size.y; j++) | |
{ | |
multiArray[i, j] = singleArray[index++]; | |
} | |
} | |
return multiArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment