fr.jeanf.questsystem 0.0.59 → 0.0.61
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/Runtime/Scripts/Core/Editor/QuestItem_Editor.cs +32 -0
- package/Runtime/Scripts/Core/Editor/QuestItem_Editor.cs.meta +11 -0
- package/Runtime/Scripts/Core/Editor/QuestStep_Editor.cs +8 -0
- package/Runtime/Scripts/Core/QuestItem.cs +35 -21
- package/Runtime/Scripts/Core/QuestStep.cs +25 -3
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#if UNITY_EDITOR
|
|
2
|
+
using UnityEditor;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
namespace jeanf.questsystem
|
|
6
|
+
{
|
|
7
|
+
[CustomEditor(typeof(QuestItem), true)]
|
|
8
|
+
public class QuestItem_Editor : Editor
|
|
9
|
+
{
|
|
10
|
+
public override void OnInspectorGUI()
|
|
11
|
+
{
|
|
12
|
+
GUILayout.Space(10);
|
|
13
|
+
var eventToSend = (QuestItem)target;
|
|
14
|
+
GUILayout.BeginHorizontal();
|
|
15
|
+
if(GUILayout.Button("Log active steps", GUILayout.Height(20))) {
|
|
16
|
+
eventToSend.LogActiveSteps(); // how do i call this?
|
|
17
|
+
}
|
|
18
|
+
var originalColor = GUI.backgroundColor;
|
|
19
|
+
GUI.backgroundColor = Color.green;
|
|
20
|
+
if (GUILayout.Button("Validate Currently Active Steps", GUILayout.Height(20)))
|
|
21
|
+
{
|
|
22
|
+
eventToSend.ValidateCurrentlyActiveSteps(); // how do i call this?
|
|
23
|
+
}
|
|
24
|
+
GUI.backgroundColor = originalColor;
|
|
25
|
+
GUILayout.EndHorizontal();
|
|
26
|
+
GUILayout.Space(10);
|
|
27
|
+
|
|
28
|
+
DrawDefaultInspector();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
#endif
|
|
@@ -11,10 +11,18 @@ namespace jeanf.questsystem
|
|
|
11
11
|
{
|
|
12
12
|
GUILayout.Space(10);
|
|
13
13
|
var eventToSend = (QuestStep)target;
|
|
14
|
+
GUILayout.BeginHorizontal();
|
|
14
15
|
if (GUILayout.Button("Regenerate questStep id", GUILayout.Height(20)))
|
|
15
16
|
{
|
|
16
17
|
eventToSend.GenerateId(); // how do i call this?
|
|
17
18
|
}
|
|
19
|
+
var originalColor = GUI.backgroundColor;
|
|
20
|
+
GUI.backgroundColor = Color.green;
|
|
21
|
+
if(GUILayout.Button("Validate step", GUILayout.Height(20))) {
|
|
22
|
+
eventToSend.FinishQuestStep(); // how do i call this?
|
|
23
|
+
}
|
|
24
|
+
GUI.backgroundColor = originalColor;
|
|
25
|
+
GUILayout.EndHorizontal();
|
|
18
26
|
GUILayout.Space(10);
|
|
19
27
|
|
|
20
28
|
DrawDefaultInspector();
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
3
4
|
using jeanf.EventSystem;
|
|
4
5
|
using UnityEngine;
|
|
5
6
|
using jeanf.propertyDrawer;
|
|
6
7
|
using jeanf.validationTools;
|
|
7
8
|
using UnityEditor;
|
|
8
|
-
using System.Linq;
|
|
9
|
-
|
|
10
9
|
|
|
11
10
|
namespace jeanf.questsystem
|
|
12
11
|
{
|
|
@@ -29,6 +28,10 @@ namespace jeanf.questsystem
|
|
|
29
28
|
private Dictionary<string, QuestStep> completedSteps = new Dictionary<string, QuestStep>();
|
|
30
29
|
private List<QuestStep> rootSteps = new List<QuestStep>();
|
|
31
30
|
|
|
31
|
+
public delegate void ValidateStep(string stepId);
|
|
32
|
+
|
|
33
|
+
public static ValidateStep ValidateStepEvent;
|
|
34
|
+
|
|
32
35
|
|
|
33
36
|
[ReadOnly] [Range(0, 1)] [SerializeField]
|
|
34
37
|
private float progress = 0.0f;
|
|
@@ -44,11 +47,14 @@ namespace jeanf.questsystem
|
|
|
44
47
|
[Header("Listening on:")]
|
|
45
48
|
[SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
|
|
46
49
|
[SerializeField] [Validation("A reference to the QuestInitialCheck SO is required")] private StringEventChannelSO QuestInitialCheck;
|
|
50
|
+
[SerializeField] private VoidEventChannelSO resetChannel;
|
|
47
51
|
|
|
48
52
|
[Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
|
|
49
53
|
private StringEventChannelSO requirementCheck;
|
|
50
54
|
[SerializeField][Validation("A reference to the LoadRequiredScenesEventChannel SO is required")] StringListEventChannelSO loadRequiredScenesEventChannel;
|
|
51
55
|
[SerializeField] IntEventChannelSO unlockDoorsEventChannel;
|
|
56
|
+
|
|
57
|
+
|
|
52
58
|
|
|
53
59
|
#region Awake/Enable/Disable
|
|
54
60
|
private void Awake()
|
|
@@ -73,25 +79,24 @@ namespace jeanf.questsystem
|
|
|
73
79
|
|
|
74
80
|
private void Subscribe()
|
|
75
81
|
{
|
|
82
|
+
resetChannel.OnEventRaised += Reset;
|
|
76
83
|
QuestInitialCheck.OnEventRaised += Init;
|
|
77
84
|
QuestProgress.OnEventRaised += UpdateProgress;
|
|
78
85
|
GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
|
|
79
86
|
GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
|
|
80
87
|
QuestStep.sendNextStepId += InstantiateQuestStep;
|
|
81
|
-
//QuestStep.stepCompleted += DestroyQuestStep;
|
|
82
88
|
QuestStep.stepActive += UpdateStepStatus;
|
|
83
89
|
QuestStep.childStep += AddStepToStepMap;
|
|
84
|
-
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
private void Unsubscribe()
|
|
88
93
|
{
|
|
94
|
+
resetChannel.OnEventRaised -= Reset;
|
|
89
95
|
QuestInitialCheck.OnEventRaised -= Init;
|
|
90
96
|
QuestProgress.OnEventRaised -= UpdateProgress;
|
|
91
97
|
GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
|
|
92
98
|
GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
|
|
93
99
|
QuestStep.sendNextStepId -= InstantiateQuestStep;
|
|
94
|
-
//QuestStep.stepCompleted -= DestroyQuestStep;
|
|
95
100
|
QuestStep.stepActive -= UpdateStepStatus;
|
|
96
101
|
QuestStep.childStep -= AddStepToStepMap;
|
|
97
102
|
|
|
@@ -99,6 +104,11 @@ namespace jeanf.questsystem
|
|
|
99
104
|
}
|
|
100
105
|
#endregion
|
|
101
106
|
|
|
107
|
+
private void Reset()
|
|
108
|
+
{
|
|
109
|
+
Init(questId);
|
|
110
|
+
}
|
|
111
|
+
|
|
102
112
|
#region Instantiations & Loading
|
|
103
113
|
public void InstantiateQuestStep(string id)
|
|
104
114
|
{
|
|
@@ -159,6 +169,14 @@ namespace jeanf.questsystem
|
|
|
159
169
|
#region quest process
|
|
160
170
|
private void Init(string id)
|
|
161
171
|
{
|
|
172
|
+
if (transform.childCount > 0)
|
|
173
|
+
{
|
|
174
|
+
for (var i = transform.childCount - 1; i >= 0; i--)
|
|
175
|
+
{
|
|
176
|
+
Destroy(transform.GetChild(i));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
162
180
|
activeSteps.Clear();
|
|
163
181
|
activeSteps.TrimExcess();
|
|
164
182
|
completedSteps.Clear();
|
|
@@ -233,6 +251,18 @@ namespace jeanf.questsystem
|
|
|
233
251
|
}
|
|
234
252
|
#endregion
|
|
235
253
|
|
|
254
|
+
public void ValidateCurrentlyActiveSteps()
|
|
255
|
+
{
|
|
256
|
+
var currentlyActiveSteps = activeSteps.Keys;
|
|
257
|
+
|
|
258
|
+
for (var i = 0; i < currentlyActiveSteps.Count; i++)
|
|
259
|
+
{
|
|
260
|
+
var activeStep = activeSteps.ElementAt(i);
|
|
261
|
+
var stepKey = activeStep.Key;
|
|
262
|
+
if(activeSteps.ContainsKey(stepKey)) ValidateStepEvent.Invoke(stepKey);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
236
266
|
#region validation tools
|
|
237
267
|
|
|
238
268
|
#if UNITY_EDITOR
|
|
@@ -338,20 +368,4 @@ namespace jeanf.questsystem
|
|
|
338
368
|
}
|
|
339
369
|
#endregion
|
|
340
370
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
#if UNITY_EDITOR
|
|
344
|
-
[CustomEditor(typeof(QuestItem))]
|
|
345
|
-
public class BoolEventOnClickEditor : Editor {
|
|
346
|
-
override public void OnInspectorGUI () {
|
|
347
|
-
DrawDefaultInspector();
|
|
348
|
-
GUILayout.Space(10);
|
|
349
|
-
var eventToSend = (QuestItem) target;
|
|
350
|
-
if(GUILayout.Button("Log active steps", GUILayout.Height(30))) {
|
|
351
|
-
eventToSend.LogActiveSteps(); // how do i call this?
|
|
352
|
-
}
|
|
353
|
-
GUILayout.Space(10);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
#endif
|
|
357
371
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
using System;
|
|
1
2
|
using jeanf.EventSystem;
|
|
2
3
|
using jeanf.propertyDrawer;
|
|
3
4
|
using UnityEngine;
|
|
@@ -5,6 +6,7 @@ using UnityEngine.Playables;
|
|
|
5
6
|
using System.Collections.Generic;
|
|
6
7
|
using GraphProcessor;
|
|
7
8
|
using jeanf.validationTools;
|
|
9
|
+
using UnityEditor;
|
|
8
10
|
|
|
9
11
|
namespace jeanf.questsystem
|
|
10
12
|
{
|
|
@@ -45,13 +47,28 @@ namespace jeanf.questsystem
|
|
|
45
47
|
|
|
46
48
|
[Header("Event Channels")]
|
|
47
49
|
[SerializeField] private StringEventChannelSO sendQuestStepTooltip;
|
|
50
|
+
[SerializeField] private StringEventChannelSO stepValidationOverride;
|
|
51
|
+
|
|
52
|
+
public void OnEnable()
|
|
53
|
+
{
|
|
54
|
+
Subscribe();
|
|
55
|
+
InitializeQuestStep();
|
|
56
|
+
}
|
|
48
57
|
|
|
58
|
+
public void OnDisable() => Unsubscribe();
|
|
49
59
|
|
|
60
|
+
public void OnDestroy() => Unsubscribe();
|
|
50
61
|
|
|
62
|
+
private void Subscribe()
|
|
63
|
+
{
|
|
64
|
+
QuestItem.ValidateStepEvent += ValidateCurrentStep;
|
|
65
|
+
if(stepValidationOverride) stepValidationOverride.OnEventRaised += ValidateCurrentStep;
|
|
66
|
+
}
|
|
51
67
|
|
|
52
|
-
|
|
68
|
+
private void Unsubscribe()
|
|
53
69
|
{
|
|
54
|
-
|
|
70
|
+
QuestItem.ValidateStepEvent -= ValidateCurrentStep;
|
|
71
|
+
if(stepValidationOverride) stepValidationOverride.OnEventRaised -= ValidateCurrentStep;
|
|
55
72
|
}
|
|
56
73
|
|
|
57
74
|
|
|
@@ -84,9 +101,14 @@ namespace jeanf.questsystem
|
|
|
84
101
|
}
|
|
85
102
|
}
|
|
86
103
|
|
|
104
|
+
public void ValidateCurrentStep(string stepId)
|
|
105
|
+
{
|
|
106
|
+
if(stepId != this.stepId)return;
|
|
107
|
+
FinishQuestStep();
|
|
108
|
+
}
|
|
87
109
|
|
|
88
110
|
|
|
89
|
-
|
|
111
|
+
public void FinishQuestStep()
|
|
90
112
|
{
|
|
91
113
|
if(isDebug) Debug.Log($" ---- Step with id: {stepId} finished. Changing status to completed", this);
|
|
92
114
|
stepStatus = QuestStepStatus.Completed;
|