-
Notifications
You must be signed in to change notification settings - Fork 3
/
DataLoader.cs
77 lines (67 loc) · 1.71 KB
/
DataLoader.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class DataLoader : MonoBehaviour {
public string DATA_FILE = "data.json";
public DataClass dataClass = new DataClass();
void Awake() {
string filePath = Path.Combine(Application.streamingAssetsPath, "Animation Data/" + DATA_FILE);
if (File.Exists(filePath)) {
string dataAsJson = File.ReadAllText(filePath);
dataClass = JsonUtility.FromJson<DataClass>(dataAsJson);
Debug.Log("Found JSON (♥_♥)");
} else {
Debug.LogError("beep beep no json!");
}
}
}
[System.Serializable]
public class DataClass {
public DataItem[] items;
}
[System.Serializable]
public class DataItem {
public string name;
public float x;
public float y;
public float z;
public float scale;
public AnimData animData;
}
[System.Serializable]
public class AnimData {
public AnimClass[] animations;
public TriggerClass[] triggers;
public TransitionClass[] transitions;
}
[System.Serializable]
public class AnimClass {
public string name;
public float fps;
public bool isLoop;
public AnimEventClass[] children;
}
[System.Serializable]
public class AnimEventClass {
public string name;
public float time;
}
[System.Serializable]
public class TriggerClass {
public float offsetX;
public float offsetY;
//change to sizeX + Y
public float scaleX;
public float scaleY;
public string name;
}
[System.Serializable]
public class TransitionClass {
public string source;
public string target;
public bool hasExitTime;
public float duration = 0;
public float exitTime = 0;
public string[] conditions;
}