-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariations.cs
41 lines (34 loc) · 948 Bytes
/
Variations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Variations : MonoBehaviour
{
public static Dictionary<Sprite, Sprite[]> variations;
public Sprite[] grass;
//MonoBehavior
private void Awake()
{
variations = new Dictionary<Sprite, Sprite[]>();
variations.Add(grass[0], GetRest(grass));
}
private static Sprite[] GetRest(Sprite[] sprites)
{
Sprite[] result = new Sprite[sprites.Length-1];
for(int i=1; i<sprites.Length; i++)
{
result[i - 1] = sprites[i];
}
return result;
}
public static Sprite GetRandomVariation(Sprite key)
{
Sprite result = key;
int length = 0;
if (variations.ContainsKey(key))
{
length = variations[key].Length;
result = variations[key][Random.Range(0, length)];
}
return result;
}
}