fr.jeanf.questsystem 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/InitializeQuestSystem.cs +2 -0
- package/Runtime/Quests/Quest_StethoscopeCheck.prefab +3 -477
- package/Runtime/Quests/Quest_VisitAllPlaces.prefab +3 -477
- package/Runtime/Quests/Quest_VisitPlaces.prefab +3 -79
- package/Runtime/Scripts/Core/Quest.cs +81 -74
- package/Runtime/Scripts/Core/QuestData.cs +14 -11
- package/Runtime/Scripts/Core/QuestInfoSO.cs +15 -26
- package/Runtime/Scripts/Core/QuestItem.cs +1 -0
- package/Runtime/Scripts/Core/QuestManager.cs +196 -178
- package/Runtime/Scripts/Core/QuestState.cs +10 -7
- package/Runtime/Scripts/Core/QuestStep.cs +35 -25
- package/Runtime/Scripts/Core/QuestStepState.cs +14 -11
- package/Runtime/Scripts/Events/GameEventsManager.cs +23 -19
- package/Runtime/Scripts/Events/QuestEvents.cs +38 -30
- package/Runtime/Scripts/Input/InputManager.cs +19 -17
- package/Runtime/Scripts/Scenarios/ScenarioManager.cs +22 -19
- package/package.json +2 -1
|
@@ -4,240 +4,258 @@ using jeanf.EventSystem;
|
|
|
4
4
|
using UnityEngine;
|
|
5
5
|
using UnityEngine.Serialization;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
namespace jeanf.questsystem
|
|
8
8
|
{
|
|
9
|
-
public
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[Header("Config")]
|
|
17
|
-
[SerializeField] private bool loadSavedQuestState = true;
|
|
18
|
-
[Header("Broadcasting on:")] [SerializeField] private StringEventChannelSO questStatusUpdateChannel;
|
|
19
|
-
[Header("Broadcasting on:")] [SerializeField] private StringFloatEventChannelSO questProgress;
|
|
9
|
+
public class QuestManager : MonoBehaviour, IDebugBehaviour
|
|
10
|
+
{
|
|
11
|
+
public bool isDebug
|
|
12
|
+
{
|
|
13
|
+
get => _isDebug;
|
|
14
|
+
set => _isDebug = value;
|
|
15
|
+
}
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
[SerializeField] private bool _isDebug = false;
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
[FormerlySerializedAs("loadQuestState")] [Header("Config")] [SerializeField]
|
|
20
|
+
private bool loadSavedQuestState = true;
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
questMap = CreateQuestMap();
|
|
29
|
-
}
|
|
22
|
+
[Header("Broadcasting on:")] [SerializeField]
|
|
23
|
+
private StringEventChannelSO questStatusUpdateChannel;
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
GameEventsManager.instance.questEvents.onStartQuest += StartQuest;
|
|
34
|
-
GameEventsManager.instance.questEvents.onAdvanceQuest += AdvanceQuest;
|
|
35
|
-
GameEventsManager.instance.questEvents.onFinishQuest += FinishQuest;
|
|
25
|
+
[Header("Broadcasting on:")] [SerializeField]
|
|
26
|
+
private StringFloatEventChannelSO questProgress;
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
private Dictionary<string, Quest> questMap;
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
// quest start requirements
|
|
31
|
+
private int currentPlayerLevel;
|
|
41
32
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
GameEventsManager.instance.questEvents.onFinishQuest -= FinishQuest;
|
|
33
|
+
private void Awake()
|
|
34
|
+
{
|
|
35
|
+
questMap = CreateQuestMap();
|
|
36
|
+
}
|
|
47
37
|
|
|
48
|
-
|
|
38
|
+
private void OnEnable()
|
|
39
|
+
{
|
|
40
|
+
GameEventsManager.instance.questEvents.onStartQuest += StartQuest;
|
|
41
|
+
GameEventsManager.instance.questEvents.onAdvanceQuest += AdvanceQuest;
|
|
42
|
+
GameEventsManager.instance.questEvents.onFinishQuest += FinishQuest;
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
}
|
|
44
|
+
GameEventsManager.instance.questEvents.onQuestStepStateChange += QuestStepStateChange;
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
foreach (Quest quest in questMap.Values)
|
|
57
|
-
{
|
|
58
|
-
// initialize any loaded quest steps
|
|
59
|
-
if (quest.state == QuestState.IN_PROGRESS)
|
|
60
|
-
{
|
|
61
|
-
quest.InstantiateCurrentQuestStep(this.transform);
|
|
62
|
-
}
|
|
63
|
-
// broadcast the initial state of all quests on startup
|
|
64
|
-
GameEventsManager.instance.questEvents.QuestStateChange(quest);
|
|
46
|
+
GameEventsManager.instance.playerEvents.onPlayerLevelChange += PlayerLevelChange;
|
|
65
47
|
}
|
|
66
|
-
}
|
|
67
48
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
49
|
+
private void OnDisable()
|
|
50
|
+
{
|
|
51
|
+
GameEventsManager.instance.questEvents.onStartQuest -= StartQuest;
|
|
52
|
+
GameEventsManager.instance.questEvents.onAdvanceQuest -= AdvanceQuest;
|
|
53
|
+
GameEventsManager.instance.questEvents.onFinishQuest -= FinishQuest;
|
|
74
54
|
|
|
75
|
-
|
|
76
|
-
{
|
|
77
|
-
currentPlayerLevel = level;
|
|
78
|
-
}
|
|
55
|
+
GameEventsManager.instance.questEvents.onQuestStepStateChange -= QuestStepStateChange;
|
|
79
56
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// check player level requirements
|
|
83
|
-
var meetsRequirements = !(currentPlayerLevel < quest.info.levelRequirement);
|
|
57
|
+
GameEventsManager.instance.playerEvents.onPlayerLevelChange -= PlayerLevelChange;
|
|
58
|
+
}
|
|
84
59
|
|
|
85
|
-
|
|
86
|
-
foreach (QuestInfoSO prerequisiteQuestInfo in quest.info.questPrerequisites)
|
|
60
|
+
private void Start()
|
|
87
61
|
{
|
|
88
|
-
|
|
62
|
+
|
|
63
|
+
foreach (Quest quest in questMap.Values)
|
|
89
64
|
{
|
|
90
|
-
|
|
65
|
+
// initialize any loaded quest steps
|
|
66
|
+
if (quest.state == QuestState.IN_PROGRESS)
|
|
67
|
+
{
|
|
68
|
+
quest.InstantiateCurrentQuestStep(this.transform);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// broadcast the initial state of all quests on startup
|
|
72
|
+
GameEventsManager.instance.questEvents.QuestStateChange(quest);
|
|
91
73
|
}
|
|
92
74
|
}
|
|
93
75
|
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
private void ChangeQuestState(string id, QuestState state)
|
|
77
|
+
{
|
|
78
|
+
Quest quest = GetQuestById(id);
|
|
79
|
+
quest.state = state;
|
|
80
|
+
GameEventsManager.instance.questEvents.QuestStateChange(quest);
|
|
81
|
+
}
|
|
96
82
|
|
|
97
|
-
|
|
98
|
-
{
|
|
99
|
-
// loop through ALL quests
|
|
100
|
-
foreach (Quest quest in questMap.Values)
|
|
83
|
+
private void PlayerLevelChange(int level)
|
|
101
84
|
{
|
|
102
|
-
|
|
103
|
-
if (quest.state == QuestState.REQUIREMENTS_NOT_MET && CheckRequirementsMet(quest))
|
|
104
|
-
{
|
|
105
|
-
ChangeQuestState(quest.info.id, QuestState.CAN_START);
|
|
106
|
-
}
|
|
85
|
+
currentPlayerLevel = level;
|
|
107
86
|
}
|
|
108
|
-
}
|
|
109
87
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
ChangeQuestState(quest.info.id, QuestState.IN_PROGRESS);
|
|
115
|
-
SaveQuest(quest);
|
|
116
|
-
}
|
|
88
|
+
private bool CheckRequirementsMet(Quest quest)
|
|
89
|
+
{
|
|
90
|
+
// check player level requirements
|
|
91
|
+
var meetsRequirements = !(currentPlayerLevel < quest.info.levelRequirement);
|
|
117
92
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
93
|
+
// check quest prerequisites for completion
|
|
94
|
+
foreach (QuestInfoSO prerequisiteQuestInfo in quest.info.questPrerequisites)
|
|
95
|
+
{
|
|
96
|
+
if (GetQuestById(prerequisiteQuestInfo.id).state != QuestState.FINISHED)
|
|
97
|
+
{
|
|
98
|
+
meetsRequirements = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
121
101
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if(isDebug) Debug.Log($"[{quest.info.id}]quest state: {quest.state} - {quest.currentStep} over {quest.info.questStepPrefabs.Length} steps done", this);
|
|
125
|
-
questStatusUpdateChannel.RaiseEvent($"[{quest.info.id}]quest state: {quest.state} - {quest.currentStep} over {quest.info.questStepPrefabs.Length} steps done");
|
|
126
|
-
var progress = (float) quest.currentStep / quest.info.questStepPrefabs.Length;
|
|
127
|
-
if(isDebug) Debug.Log($"[{quest.info.id}] progress: {progress*100}%", this);
|
|
128
|
-
questProgress.RaiseEvent(quest.info.id, progress);
|
|
102
|
+
return meetsRequirements;
|
|
103
|
+
}
|
|
129
104
|
|
|
130
|
-
|
|
131
|
-
if (quest.CurrentStepExists())
|
|
105
|
+
private void Update()
|
|
132
106
|
{
|
|
133
|
-
|
|
107
|
+
// loop through ALL quests
|
|
108
|
+
foreach (Quest quest in questMap.Values)
|
|
109
|
+
{
|
|
110
|
+
// if we're now meeting the requirements, switch over to the CAN_START state
|
|
111
|
+
if (quest.state == QuestState.REQUIREMENTS_NOT_MET && CheckRequirementsMet(quest))
|
|
112
|
+
{
|
|
113
|
+
ChangeQuestState(quest.info.id, QuestState.CAN_START);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
134
116
|
}
|
|
135
|
-
|
|
136
|
-
|
|
117
|
+
|
|
118
|
+
private void StartQuest(string id)
|
|
137
119
|
{
|
|
138
|
-
|
|
120
|
+
Quest quest = GetQuestById(id);
|
|
121
|
+
quest.InstantiateCurrentQuestStep(this.transform);
|
|
122
|
+
ChangeQuestState(quest.info.id, QuestState.IN_PROGRESS);
|
|
123
|
+
SaveQuest(quest);
|
|
139
124
|
}
|
|
140
|
-
SaveQuest(quest);
|
|
141
|
-
}
|
|
142
125
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
ClaimRewards(quest);
|
|
147
|
-
ChangeQuestState(quest.info.id, QuestState.FINISHED);
|
|
148
|
-
questStatusUpdateChannel.RaiseEvent($"[{quest.info.id}] quest is finished.");
|
|
149
|
-
questProgress.RaiseEvent(quest.info.id,1);
|
|
150
|
-
SaveQuest(quest);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private void ClaimRewards(Quest quest)
|
|
154
|
-
{
|
|
155
|
-
GameEventsManager.instance.scenarioEvents.ScenarioUnlocked(quest.info.unlockedScenario);
|
|
156
|
-
}
|
|
126
|
+
private void AdvanceQuest(string id)
|
|
127
|
+
{
|
|
128
|
+
Quest quest = GetQuestById(id);
|
|
157
129
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
130
|
+
// move on to the next step
|
|
131
|
+
quest.MoveToNextStep();
|
|
132
|
+
if (isDebug)
|
|
133
|
+
Debug.Log(
|
|
134
|
+
$"[{quest.info.id}]quest state: {quest.state} - {quest.currentStep} over {quest.info.questStepPrefabs.Length} steps done",
|
|
135
|
+
this);
|
|
136
|
+
questStatusUpdateChannel.RaiseEvent(
|
|
137
|
+
$"[{quest.info.id}]quest state: {quest.state} - {quest.currentStep} over {quest.info.questStepPrefabs.Length} steps done");
|
|
138
|
+
var progress = (float)quest.currentStep / quest.info.questStepPrefabs.Length;
|
|
139
|
+
if (isDebug) Debug.Log($"[{quest.info.id}] progress: {progress * 100}%", this);
|
|
140
|
+
questProgress.RaiseEvent(quest.info.id, progress);
|
|
164
141
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// loads all QuestInfoSO Scriptable Objects under the Assets/Resources/Quests folder
|
|
168
|
-
QuestInfoSO[] allQuests = Resources.LoadAll<QuestInfoSO>("Quests");
|
|
169
|
-
// Create the quest map
|
|
170
|
-
Dictionary<string, Quest> idToQuestMap = new Dictionary<string, Quest>();
|
|
171
|
-
foreach (QuestInfoSO questInfo in allQuests)
|
|
172
|
-
{
|
|
173
|
-
if (idToQuestMap.ContainsKey(questInfo.id))
|
|
142
|
+
// if there are more steps, instantiate the next one
|
|
143
|
+
if (quest.CurrentStepExists())
|
|
174
144
|
{
|
|
175
|
-
|
|
145
|
+
quest.InstantiateCurrentQuestStep(this.transform);
|
|
176
146
|
}
|
|
177
|
-
|
|
147
|
+
// if there are no more steps, then we've finished all of them for this quest
|
|
148
|
+
else
|
|
149
|
+
{
|
|
150
|
+
ChangeQuestState(quest.info.id, QuestState.CAN_FINISH);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
SaveQuest(quest);
|
|
178
154
|
}
|
|
179
|
-
return idToQuestMap;
|
|
180
|
-
}
|
|
181
155
|
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
Quest quest = questMap[id];
|
|
185
|
-
if (quest == null)
|
|
156
|
+
private void FinishQuest(string id)
|
|
186
157
|
{
|
|
187
|
-
|
|
158
|
+
Quest quest = GetQuestById(id);
|
|
159
|
+
ClaimRewards(quest);
|
|
160
|
+
ChangeQuestState(quest.info.id, QuestState.FINISHED);
|
|
161
|
+
questStatusUpdateChannel.RaiseEvent($"[{quest.info.id}] quest is finished.");
|
|
162
|
+
questProgress.RaiseEvent(quest.info.id, 1);
|
|
163
|
+
SaveQuest(quest);
|
|
188
164
|
}
|
|
189
|
-
return quest;
|
|
190
|
-
}
|
|
191
165
|
|
|
192
|
-
|
|
193
|
-
{
|
|
194
|
-
foreach (Quest quest in questMap.Values)
|
|
166
|
+
private void ClaimRewards(Quest quest)
|
|
195
167
|
{
|
|
196
|
-
|
|
168
|
+
GameEventsManager.instance.scenarioEvents.ScenarioUnlocked(quest.info.unlockedScenario);
|
|
197
169
|
}
|
|
198
|
-
}
|
|
199
170
|
|
|
200
|
-
|
|
201
|
-
{
|
|
202
|
-
try
|
|
171
|
+
private void QuestStepStateChange(string id, int stepIndex, QuestStepState questStepState)
|
|
203
172
|
{
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
Debug.Log($"saved data {serializedData}");
|
|
208
|
-
// saving to PlayerPrefs is just a quick example for this tutorial video,
|
|
209
|
-
// you probably don't want to save this info there long-term.
|
|
210
|
-
// instead, use an actual Save & Load system and write to a file, the cloud, etc..
|
|
211
|
-
PlayerPrefs.SetString(quest.info.id, serializedData);
|
|
173
|
+
Quest quest = GetQuestById(id);
|
|
174
|
+
quest.StoreQuestStepState(questStepState, stepIndex);
|
|
175
|
+
ChangeQuestState(id, quest.state);
|
|
212
176
|
}
|
|
213
|
-
|
|
177
|
+
|
|
178
|
+
private Dictionary<string, Quest> CreateQuestMap()
|
|
214
179
|
{
|
|
215
|
-
|
|
180
|
+
// loads all QuestInfoSO Scriptable Objects under the Assets/Resources/Quests folder
|
|
181
|
+
QuestInfoSO[] allQuests = Resources.LoadAll<QuestInfoSO>("Quests");
|
|
182
|
+
// Create the quest map
|
|
183
|
+
Dictionary<string, Quest> idToQuestMap = new Dictionary<string, Quest>();
|
|
184
|
+
foreach (QuestInfoSO questInfo in allQuests)
|
|
185
|
+
{
|
|
186
|
+
if (idToQuestMap.ContainsKey(questInfo.id))
|
|
187
|
+
{
|
|
188
|
+
Debug.LogWarning("Duplicate ID found when creating quest map: " + questInfo.id);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
idToQuestMap.Add(questInfo.id, LoadQuest(questInfo));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return idToQuestMap;
|
|
216
195
|
}
|
|
217
|
-
}
|
|
218
196
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
197
|
+
private Quest GetQuestById(string id)
|
|
198
|
+
{
|
|
199
|
+
Quest quest = questMap[id];
|
|
200
|
+
if (quest == null)
|
|
201
|
+
{
|
|
202
|
+
Debug.LogError("ID not found in the Quest Map: " + id);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return quest;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private void OnApplicationQuit()
|
|
209
|
+
{
|
|
210
|
+
foreach (Quest quest in questMap.Values)
|
|
211
|
+
{
|
|
212
|
+
SaveQuest(quest);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private void SaveQuest(Quest quest)
|
|
223
217
|
{
|
|
224
|
-
|
|
225
|
-
if (PlayerPrefs.HasKey(questInfo.id) && loadSavedQuestState)
|
|
218
|
+
try
|
|
226
219
|
{
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
220
|
+
QuestData questData = quest.GetQuestData();
|
|
221
|
+
// serialize using JsonUtility, but use whatever you want here (like JSON.NET)
|
|
222
|
+
string serializedData = JsonUtility.ToJson(questData);
|
|
223
|
+
Debug.Log($"saved data {serializedData}");
|
|
224
|
+
// saving to PlayerPrefs is just a quick example for this tutorial video,
|
|
225
|
+
// you probably don't want to save this info there long-term.
|
|
226
|
+
// instead, use an actual Save & Load system and write to a file, the cloud, etc..
|
|
227
|
+
PlayerPrefs.SetString(quest.info.id, serializedData);
|
|
230
228
|
}
|
|
231
|
-
|
|
232
|
-
else
|
|
229
|
+
catch (System.Exception e)
|
|
233
230
|
{
|
|
234
|
-
quest
|
|
231
|
+
Debug.LogError("Failed to save quest with id " + quest.info.id + ": " + e);
|
|
235
232
|
}
|
|
236
233
|
}
|
|
237
|
-
|
|
234
|
+
|
|
235
|
+
private Quest LoadQuest(QuestInfoSO questInfo)
|
|
238
236
|
{
|
|
239
|
-
|
|
237
|
+
Quest quest = null;
|
|
238
|
+
try
|
|
239
|
+
{
|
|
240
|
+
// load quest from saved data
|
|
241
|
+
if (PlayerPrefs.HasKey(questInfo.id) && loadSavedQuestState)
|
|
242
|
+
{
|
|
243
|
+
string serializedData = PlayerPrefs.GetString(questInfo.id);
|
|
244
|
+
QuestData questData = JsonUtility.FromJson<QuestData>(serializedData);
|
|
245
|
+
quest = new Quest(questInfo, questData.state, questData.questStepIndex, questData.questStepStates);
|
|
246
|
+
}
|
|
247
|
+
// otherwise, initialize a new quest
|
|
248
|
+
else
|
|
249
|
+
{
|
|
250
|
+
quest = new Quest(questInfo);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (System.Exception e)
|
|
254
|
+
{
|
|
255
|
+
Debug.LogError("Failed to load quest with id " + quest.info.id + ": " + e);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return quest;
|
|
240
259
|
}
|
|
241
|
-
return quest;
|
|
242
260
|
}
|
|
243
|
-
}
|
|
261
|
+
}
|
|
@@ -2,11 +2,14 @@ using System.Collections;
|
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using UnityEngine;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
namespace jeanf.questsystem
|
|
6
6
|
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
public enum QuestState
|
|
8
|
+
{
|
|
9
|
+
REQUIREMENTS_NOT_MET,
|
|
10
|
+
CAN_START,
|
|
11
|
+
IN_PROGRESS,
|
|
12
|
+
CAN_FINISH,
|
|
13
|
+
FINISHED
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,38 +1,48 @@
|
|
|
1
1
|
using System.Collections;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
using jeanf.EventSystem;
|
|
4
|
+
using jeanf.propertyDrawer ;
|
|
3
5
|
using UnityEngine;
|
|
6
|
+
using jeanf.propertyDrawer;
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
namespace jeanf.questsystem
|
|
6
9
|
{
|
|
7
|
-
|
|
8
|
-
private string questId;
|
|
9
|
-
private int stepIndex;
|
|
10
|
-
private float questStepProgress = 0;
|
|
11
|
-
|
|
12
|
-
public void InitializeQuestStep(string questId, int stepIndex, string questStepState)
|
|
10
|
+
public abstract class QuestStep : MonoBehaviour
|
|
13
11
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
private bool isFinished = false;
|
|
13
|
+
private string questId;
|
|
14
|
+
private int stepIndex;
|
|
15
|
+
private float questStepProgress = 0;
|
|
16
|
+
|
|
17
|
+
[SerializeField] private bool sendEventOnInit = false;
|
|
18
|
+
//[DrawIf("sendEventOnInit", true, ComparisonType.Equals)]
|
|
19
|
+
|
|
20
|
+
public void InitializeQuestStep(string questId, int stepIndex, string questStepState)
|
|
17
21
|
{
|
|
18
|
-
|
|
22
|
+
this.questId = questId;
|
|
23
|
+
this.stepIndex = stepIndex;
|
|
24
|
+
if (questStepState != null && questStepState != "")
|
|
25
|
+
{
|
|
26
|
+
SetQuestStepState(questStepState);
|
|
27
|
+
}
|
|
19
28
|
}
|
|
20
|
-
}
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
if (!isFinished)
|
|
30
|
+
protected void FinishQuestStep()
|
|
25
31
|
{
|
|
26
|
-
isFinished
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
if (!isFinished)
|
|
33
|
+
{
|
|
34
|
+
isFinished = true;
|
|
35
|
+
GameEventsManager.instance.questEvents.AdvanceQuest(questId);
|
|
36
|
+
Destroy(this.gameObject);
|
|
37
|
+
}
|
|
29
38
|
}
|
|
30
|
-
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
protected void ChangeState(string newState)
|
|
41
|
+
{
|
|
42
|
+
GameEventsManager.instance.questEvents.QuestStepStateChange(questId, stepIndex,
|
|
43
|
+
new QuestStepState(newState));
|
|
44
|
+
}
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
}
|
|
46
|
+
protected abstract void SetQuestStepState(string state);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -2,18 +2,21 @@ using System.Collections;
|
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using UnityEngine;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
public class QuestStepState
|
|
5
|
+
namespace jeanf.questsystem
|
|
7
6
|
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
public QuestStepState(string state)
|
|
7
|
+
[System.Serializable]
|
|
8
|
+
public class QuestStepState
|
|
11
9
|
{
|
|
12
|
-
|
|
13
|
-
}
|
|
10
|
+
public string state;
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
public QuestStepState(string state)
|
|
13
|
+
{
|
|
14
|
+
this.state = state;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public QuestStepState()
|
|
18
|
+
{
|
|
19
|
+
this.state = "";
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
|
-
}
|
|
22
|
+
}
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using UnityEngine;
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
namespace jeanf.questsystem
|
|
5
5
|
{
|
|
6
|
-
public
|
|
6
|
+
public class GameEventsManager : MonoBehaviour
|
|
7
|
+
{
|
|
8
|
+
public static GameEventsManager instance { get; private set; }
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
public InputEvents inputEvents;
|
|
11
|
+
public PlayerEvents playerEvents;
|
|
12
|
+
public ScenarioEvents scenarioEvents;
|
|
13
|
+
public MiscEvents miscEvents;
|
|
14
|
+
public QuestEvents questEvents;
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
if (instance != null)
|
|
16
|
+
private void Awake()
|
|
17
17
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (instance != null)
|
|
19
|
+
{
|
|
20
|
+
Debug.LogError("Found more than one Game Events Manager in the scene.");
|
|
21
|
+
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
instance = this;
|
|
24
|
+
|
|
25
|
+
// initialize all events
|
|
26
|
+
inputEvents = new InputEvents();
|
|
27
|
+
playerEvents = new PlayerEvents();
|
|
28
|
+
scenarioEvents = new ScenarioEvents();
|
|
29
|
+
miscEvents = new MiscEvents();
|
|
30
|
+
questEvents = new QuestEvents();
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
}
|