37 lines
1022 B
C#
37 lines
1022 B
C#
using System;
|
|
using System.Linq;
|
|
using Enums;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace Utils {
|
|
public static class RandomUtils {
|
|
private static readonly GemType[] spawnableGems = BuildSpawnableGems();
|
|
|
|
private static GemType[] BuildSpawnableGems() {
|
|
Array values = Enum.GetValues(typeof(GemType));
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < values.Length; i++) {
|
|
if ((GemType)values.GetValue(i) != GemType.Bomb)
|
|
count++;
|
|
}
|
|
|
|
GemType[] result = new GemType[count];
|
|
int write = 0;
|
|
|
|
for (int i = 0; i < values.Length; i++) {
|
|
GemType t = (GemType)values.GetValue(i);
|
|
if (t == GemType.Bomb)
|
|
continue;
|
|
|
|
result[write++] = t;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static GemType RandomGemType() {
|
|
return spawnableGems[Random.Range(0, spawnableGems.Length)];
|
|
}
|
|
}
|
|
} |