fr.jeanf.questsystem 0.0.4 → 0.0.6
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/QuestInfoSO_Editor.cs +23 -0
- package/Runtime/Scripts/Core/Editor/QuestInfoSO_Editor.cs.meta +11 -0
- package/Runtime/Scripts/Core/Editor.meta +8 -0
- package/Runtime/Scripts/Core/Quest.cs +15 -0
- package/Runtime/Scripts/Core/QuestInfoSO.cs +24 -4
- package/Runtime/Scripts/Core/QuestManager.cs +16 -5
- package/Runtime/Scripts/Core/QuestStep.cs +20 -5
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
#if UNITY_EDITOR
|
|
3
|
+
using jeanf.questsystem;
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
public class QuestInfoSO_Editor : Editor
|
|
8
|
+
{
|
|
9
|
+
[CustomEditor(typeof(QuestInfoSO))]
|
|
10
|
+
public class BoolEventOnClickEditor : Editor {
|
|
11
|
+
override public void OnInspectorGUI () {
|
|
12
|
+
GUILayout.Space(10);
|
|
13
|
+
var eventToSend = (QuestInfoSO)target;
|
|
14
|
+
if(GUILayout.Button("Regenerate quest id", GUILayout.Height(20))) {
|
|
15
|
+
eventToSend.GenerateId(); // how do i call this?
|
|
16
|
+
}
|
|
17
|
+
GUILayout.Space(10);
|
|
18
|
+
|
|
19
|
+
DrawDefaultInspector();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
#endif
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
using System.Collections;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
using jeanf.EventSystem;
|
|
4
|
+
using jeanf.propertyDrawer;
|
|
3
5
|
using UnityEngine;
|
|
4
6
|
|
|
5
7
|
namespace jeanf.questsystem
|
|
@@ -14,6 +16,11 @@ namespace jeanf.questsystem
|
|
|
14
16
|
private int currentQuestStepIndex;
|
|
15
17
|
public int currentStep;
|
|
16
18
|
private QuestStepState[] questStepStates;
|
|
19
|
+
public StringEventChannelSO messageChannel;
|
|
20
|
+
public bool sendMessageOnInitialization = false;
|
|
21
|
+
public string messageToSendOnInit = "";
|
|
22
|
+
public bool sendMessageOnFinish = false;
|
|
23
|
+
public string messageToSendOnFinish = "";
|
|
17
24
|
|
|
18
25
|
public Quest(QuestInfoSO questInfo)
|
|
19
26
|
{
|
|
@@ -21,6 +28,13 @@ namespace jeanf.questsystem
|
|
|
21
28
|
this.state = QuestState.REQUIREMENTS_NOT_MET;
|
|
22
29
|
this.currentQuestStepIndex = currentStep = 0;
|
|
23
30
|
this.questStepStates = new QuestStepState[info.questStepPrefabs.Length];
|
|
31
|
+
this.messageChannel = questInfo.messageChannel;
|
|
32
|
+
//init
|
|
33
|
+
this.sendMessageOnInitialization = questInfo.sendMessageOnInitialization;
|
|
34
|
+
this.messageToSendOnInit = questInfo.messageToSendOnInitialization;
|
|
35
|
+
//finish
|
|
36
|
+
this.sendMessageOnFinish = questInfo.sendMessageOnFinish;
|
|
37
|
+
this.messageToSendOnFinish = questInfo.messageToSendOnFinish;
|
|
24
38
|
for (int i = 0; i < questStepStates.Length; i++)
|
|
25
39
|
{
|
|
26
40
|
questStepStates[i] = new QuestStepState();
|
|
@@ -47,6 +61,7 @@ namespace jeanf.questsystem
|
|
|
47
61
|
}
|
|
48
62
|
}
|
|
49
63
|
|
|
64
|
+
|
|
50
65
|
public void MoveToNextStep()
|
|
51
66
|
{
|
|
52
67
|
currentQuestStepIndex++;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
using System
|
|
2
|
-
using
|
|
3
|
-
using UnityEngine;
|
|
1
|
+
using System;
|
|
2
|
+
using jeanf.EventSystem;
|
|
3
|
+
using UnityEngine;
|
|
4
4
|
using jeanf.propertyDrawer;
|
|
5
5
|
|
|
6
6
|
namespace jeanf.questsystem
|
|
@@ -9,9 +9,16 @@ using UnityEngine;
|
|
|
9
9
|
[ScriptableObjectDrawer]
|
|
10
10
|
public class QuestInfoSO : ScriptableObject
|
|
11
11
|
{
|
|
12
|
-
[field: SerializeField] public string id { get; private set; }
|
|
12
|
+
[field: Space(10)][field: ReadOnly] [field: SerializeField] public string id { get; private set; }
|
|
13
13
|
|
|
14
14
|
[Header("General")] public string displayName;
|
|
15
|
+
|
|
16
|
+
[Header("Custom messages init/finish")]
|
|
17
|
+
[SerializeField] public StringEventChannelSO messageChannel;
|
|
18
|
+
[SerializeField] public bool sendMessageOnInitialization = false;
|
|
19
|
+
[SerializeField] public string messageToSendOnInitialization = "";
|
|
20
|
+
[SerializeField] public bool sendMessageOnFinish = false;
|
|
21
|
+
[SerializeField] public string messageToSendOnFinish = "";
|
|
15
22
|
|
|
16
23
|
[Header("Requirements")] public int levelRequirement;
|
|
17
24
|
public QuestInfoSO[] questPrerequisites;
|
|
@@ -19,5 +26,18 @@ using UnityEngine;
|
|
|
19
26
|
[Header("Steps")] public GameObject[] questStepPrefabs;
|
|
20
27
|
|
|
21
28
|
[Header("Rewards")] public string unlockedScenario;
|
|
29
|
+
|
|
30
|
+
#if UNITY_EDITOR
|
|
31
|
+
private void OnValidate()
|
|
32
|
+
{
|
|
33
|
+
if (id == string.Empty || id == null) GenerateId();
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
public void GenerateId()
|
|
38
|
+
{
|
|
39
|
+
id = $"{System.Guid.NewGuid()}";
|
|
40
|
+
UnityEditor.EditorUtility.SetDirty(this);
|
|
41
|
+
}
|
|
22
42
|
}
|
|
23
43
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
using System;
|
|
1
2
|
using System.Collections;
|
|
2
3
|
using System.Collections.Generic;
|
|
3
4
|
using jeanf.EventSystem;
|
|
@@ -21,8 +22,6 @@ namespace jeanf.questsystem
|
|
|
21
22
|
|
|
22
23
|
[Header("Broadcasting on:")] [SerializeField]
|
|
23
24
|
private StringEventChannelSO questStatusUpdateChannel;
|
|
24
|
-
|
|
25
|
-
[Header("Broadcasting on:")] [SerializeField]
|
|
26
25
|
private StringFloatEventChannelSO questProgress;
|
|
27
26
|
|
|
28
27
|
private Dictionary<string, Quest> questMap;
|
|
@@ -121,6 +120,9 @@ namespace jeanf.questsystem
|
|
|
121
120
|
quest.InstantiateCurrentQuestStep(this.transform);
|
|
122
121
|
ChangeQuestState(quest.info.id, QuestState.IN_PROGRESS);
|
|
123
122
|
SaveQuest(quest);
|
|
123
|
+
if (!quest.sendMessageOnInitialization) return;
|
|
124
|
+
quest.messageChannel.RaiseEvent(quest.messageToSendOnInit);
|
|
125
|
+
if(isDebug) Debug.Log($"quest id:{id} started, a message was attatched to the initialization: {quest.messageToSendOnInit}");
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
private void AdvanceQuest(string id)
|
|
@@ -135,13 +137,12 @@ namespace jeanf.questsystem
|
|
|
135
137
|
this);
|
|
136
138
|
questStatusUpdateChannel.RaiseEvent(
|
|
137
139
|
$"[{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);
|
|
141
140
|
|
|
141
|
+
|
|
142
142
|
// if there are more steps, instantiate the next one
|
|
143
143
|
if (quest.CurrentStepExists())
|
|
144
144
|
{
|
|
145
|
+
UpdateProgress(quest);
|
|
145
146
|
quest.InstantiateCurrentQuestStep(this.transform);
|
|
146
147
|
}
|
|
147
148
|
// if there are no more steps, then we've finished all of them for this quest
|
|
@@ -153,14 +154,24 @@ namespace jeanf.questsystem
|
|
|
153
154
|
SaveQuest(quest);
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
private void UpdateProgress(Quest quest)
|
|
158
|
+
{
|
|
159
|
+
var progress = (float)quest.currentStep / quest.info.questStepPrefabs.Length;
|
|
160
|
+
if (quest.info.id == null) Debug.Log("C'est null");;
|
|
161
|
+
if (isDebug) Debug.Log($"[{quest.info.id}] progress: {progress * 100}%", this);
|
|
162
|
+
questProgress.RaiseEvent(quest.info.id, progress);
|
|
163
|
+
}
|
|
164
|
+
|
|
156
165
|
private void FinishQuest(string id)
|
|
157
166
|
{
|
|
158
167
|
Quest quest = GetQuestById(id);
|
|
168
|
+
UpdateProgress(quest);
|
|
159
169
|
ClaimRewards(quest);
|
|
160
170
|
ChangeQuestState(quest.info.id, QuestState.FINISHED);
|
|
161
171
|
questStatusUpdateChannel.RaiseEvent($"[{quest.info.id}] quest is finished.");
|
|
162
172
|
questProgress.RaiseEvent(quest.info.id, 1);
|
|
163
173
|
SaveQuest(quest);
|
|
174
|
+
if (!quest.sendMessageOnFinish) return;
|
|
164
175
|
}
|
|
165
176
|
|
|
166
177
|
private void ClaimRewards(Quest quest)
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
using System.Collections;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
1
|
using jeanf.EventSystem;
|
|
4
2
|
using jeanf.propertyDrawer ;
|
|
5
3
|
using UnityEngine;
|
|
6
|
-
using
|
|
4
|
+
using UnityEngine.Playables;
|
|
7
5
|
|
|
8
6
|
namespace jeanf.questsystem
|
|
9
7
|
{
|
|
@@ -13,9 +11,15 @@ namespace jeanf.questsystem
|
|
|
13
11
|
private string questId;
|
|
14
12
|
private int stepIndex;
|
|
15
13
|
private float questStepProgress = 0;
|
|
14
|
+
|
|
15
|
+
[Tooltip("This boolean has to be enabled if the quest step has an intro timeline.")]
|
|
16
|
+
public bool isUsingIntroTimeline = false;
|
|
17
|
+
|
|
18
|
+
[DrawIf("isUsingIntroTimeline", true, ComparisonType.Equals, DisablingType.DontDraw)]
|
|
19
|
+
[SerializeField] private TimelineTriggerEventChannelSO _timelineTriggerEventChannelSo;
|
|
20
|
+
[DrawIf("isUsingIntroTimeline", true, ComparisonType.Equals, DisablingType.DontDraw)]
|
|
21
|
+
[SerializeField] private PlayableAsset timeline;
|
|
16
22
|
|
|
17
|
-
[SerializeField] private bool sendEventOnInit = false;
|
|
18
|
-
//[DrawIf("sendEventOnInit", true, ComparisonType.Equals)]
|
|
19
23
|
|
|
20
24
|
public void InitializeQuestStep(string questId, int stepIndex, string questStepState)
|
|
21
25
|
{
|
|
@@ -25,6 +29,11 @@ namespace jeanf.questsystem
|
|
|
25
29
|
{
|
|
26
30
|
SetQuestStepState(questStepState);
|
|
27
31
|
}
|
|
32
|
+
|
|
33
|
+
if (isUsingIntroTimeline && timeline)
|
|
34
|
+
{
|
|
35
|
+
_timelineTriggerEventChannelSo.RaiseEvent(timeline, true);
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
protected void FinishQuestStep()
|
|
@@ -34,6 +43,12 @@ namespace jeanf.questsystem
|
|
|
34
43
|
isFinished = true;
|
|
35
44
|
GameEventsManager.instance.questEvents.AdvanceQuest(questId);
|
|
36
45
|
Destroy(this.gameObject);
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if (isUsingIntroTimeline && timeline)
|
|
49
|
+
{
|
|
50
|
+
_timelineTriggerEventChannelSo.RaiseEvent(timeline, false);
|
|
51
|
+
}
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
54
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name":"fr.jeanf.questsystem",
|
|
3
|
-
"version":"0.0.
|
|
3
|
+
"version":"0.0.6",
|
|
4
4
|
"displayName":"Quest system",
|
|
5
5
|
"description":"This package uses Scriptable Objects to define quests.",
|
|
6
6
|
"unity": "2021.3",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url":"https://jeanfrancoisrobin.art"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"fr.jeanf.propertydrawer": "1.1.
|
|
17
|
+
"fr.jeanf.propertydrawer": "1.1.6"
|
|
18
18
|
},
|
|
19
19
|
"samples": [
|
|
20
20
|
|