-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameDataSource.cs
163 lines (129 loc) · 5.24 KB
/
GameDataSource.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using Unity.BossRoom.Gameplay.Actions;
using Unity.BossRoom.Gameplay.Configuration;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using UnityEngine;
using Action = Unity.BossRoom.Gameplay.Actions.Action;
namespace Unity.BossRoom.Gameplay.GameplayObjects
{
public class GameDataSource : MonoBehaviour
{
/// <summary>
/// static accessor for all GameData.
/// </summary>
public static GameDataSource Instance { get; private set; }
[Header("Character classes")]
[Tooltip("All CharacterClass data should be slotted in here")]
[SerializeField]
private CharacterClass[] m_CharacterData;
Dictionary<CharacterTypeEnum, CharacterClass> m_CharacterDataMap;
//Actions that are directly listed here will get automatically assigned ActionIDs and they don't need to be a part of m_ActionPrototypes array
[Header("Common action prototypes")]
[SerializeField]
Action m_GeneralChaseActionPrototype;
[SerializeField]
Action m_GeneralTargetActionPrototype;
[SerializeField]
Action m_Emote1ActionPrototype;
[SerializeField]
Action m_Emote2ActionPrototype;
[SerializeField]
Action m_Emote3ActionPrototype;
[SerializeField]
Action m_Emote4ActionPrototype;
[SerializeField]
Action m_ReviveActionPrototype;
[SerializeField]
Action m_StunnedActionPrototype;
[SerializeField]
Action m_DropActionPrototype;
[SerializeField]
Action m_PickUpActionPrototype;
[Tooltip("All Action prototype scriptable objects should be slotted in here")]
[SerializeField]
private Action[] m_ActionPrototypes;
public Action GeneralChaseActionPrototype => m_GeneralChaseActionPrototype;
public Action GeneralTargetActionPrototype => m_GeneralTargetActionPrototype;
public Action Emote1ActionPrototype => m_Emote1ActionPrototype;
public Action Emote2ActionPrototype => m_Emote2ActionPrototype;
public Action Emote3ActionPrototype => m_Emote3ActionPrototype;
public Action Emote4ActionPrototype => m_Emote4ActionPrototype;
public Action ReviveActionPrototype => m_ReviveActionPrototype;
public Action StunnedActionPrototype => m_StunnedActionPrototype;
public Action DropActionPrototype => m_DropActionPrototype;
public Action PickUpActionPrototype => m_PickUpActionPrototype;
List<Action> m_AllActions;
public Action GetActionPrototypeByID(ActionID index)
{
return m_AllActions[index.ID];
}
public bool TryGetActionPrototypeByID(ActionID index, out Action action)
{
for (int i = 0; i < m_AllActions.Count; i++)
{
if (m_AllActions[i].ActionID == index)
{
action = m_AllActions[i];
return true;
}
}
action = null;
return false;
}
/// <summary>
/// Contents of the CharacterData list, indexed by CharacterType for convenience.
/// </summary>
public Dictionary<CharacterTypeEnum, CharacterClass> CharacterDataByType
{
get
{
if (m_CharacterDataMap == null)
{
m_CharacterDataMap = new Dictionary<CharacterTypeEnum, CharacterClass>();
foreach (CharacterClass data in m_CharacterData)
{
if (m_CharacterDataMap.ContainsKey(data.CharacterType))
{
throw new System.Exception($"Duplicate character definition detected: {data.CharacterType}");
}
m_CharacterDataMap[data.CharacterType] = data;
}
}
return m_CharacterDataMap;
}
}
private void Awake()
{
if (Instance != null)
{
throw new System.Exception("Multiple GameDataSources defined!");
}
BuildActionIDs();
DontDestroyOnLoad(gameObject);
Instance = this;
}
void BuildActionIDs()
{
var uniqueActions = new HashSet<Action>(m_ActionPrototypes);
uniqueActions.Add(GeneralChaseActionPrototype);
uniqueActions.Add(GeneralTargetActionPrototype);
uniqueActions.Add(Emote1ActionPrototype);
uniqueActions.Add(Emote2ActionPrototype);
uniqueActions.Add(Emote3ActionPrototype);
uniqueActions.Add(Emote4ActionPrototype);
uniqueActions.Add(ReviveActionPrototype);
uniqueActions.Add(StunnedActionPrototype);
uniqueActions.Add(DropActionPrototype);
uniqueActions.Add(PickUpActionPrototype);
m_AllActions = new List<Action>(uniqueActions.Count);
int i = 0;
foreach (var uniqueAction in uniqueActions)
{
uniqueAction.ActionID = new ActionID { ID = i };
m_AllActions.Add(uniqueAction);
i++;
}
}
}
}