Created
November 14, 2017 14:34
-
-
Save nicloay/a473e41da38b1c8bc621edd778deb800 to your computer and use it in GitHub Desktop.
array utilities
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
using UnityEngine; | |
public static class ArrayUtil { | |
public static int[] GetSequenceArray(int length) | |
{ | |
int[] result = new int[length]; | |
for (int i = 0; i < length; i++) | |
{ | |
result[i] = i; | |
} | |
return result; | |
} | |
public static void ShuffleArray<T>(T[] array) | |
{ | |
if (array == null || array.Length < 2) | |
{ | |
return; //do nothing | |
} | |
T temp; | |
for (int i = 0; i < array.Length; i++) | |
{ | |
temp = array[i]; | |
int rndId = Random.Range(0, array.Length); | |
array[i] = array[rndId]; | |
array[rndId] = temp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment