fr.jeanf.questsystem 0.0.1 → 0.0.3
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 +76 -0
- package/Editor/InitializeQuestSystem.cs.meta +11 -0
- package/Editor.meta +8 -0
- package/Runtime/Quests/Quest_StethoscopeCheck.prefab +2 -2
- package/Runtime/Quests/Quest_VisitAllPlaces.prefab +2 -2
- package/Runtime/Quests/Quest_VisitPlaces.prefab +2 -2
- package/Runtime/Scripts/Core/QuestItem.cs +103 -86
- package/Runtime/Scripts/quests/Quest_StethoscopeCheck.prefab +2 -2
- package/Runtime/Scripts/quests/Quest_VisitAllPlaces.prefab +2 -2
- package/Runtime/Scripts/quests/Quest_VisitPlaces.prefab +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
using System.IO;
|
|
2
|
+
using jeanf.EventSystem;
|
|
3
|
+
using UnityEditor;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
|
|
6
|
+
namespace jeanf.questsystem
|
|
7
|
+
{
|
|
8
|
+
public class InitializeQuestSystem : MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
#if UNITY_EDITOR
|
|
11
|
+
[MenuItem("GameObject/Initialize Quest System")]
|
|
12
|
+
private static void initializeQuestSystem()
|
|
13
|
+
{
|
|
14
|
+
var folder = "Quests";
|
|
15
|
+
var questFolderPath = $"Assets/Resources/{folder}";
|
|
16
|
+
|
|
17
|
+
var channelFolder = "Channels";
|
|
18
|
+
var channelFolderPath = $"{questFolderPath}/{channelFolder}";
|
|
19
|
+
|
|
20
|
+
// files needed
|
|
21
|
+
var questProgressChannel = $"QuestsProgressChannel.asset";
|
|
22
|
+
var startQuestEventChannel = $"StartQuestEventChannel.asset";
|
|
23
|
+
|
|
24
|
+
if (!AssetDatabase.IsValidFolder(questFolderPath))
|
|
25
|
+
{
|
|
26
|
+
AssetDatabase.CreateFolder("Assets/Resources", folder);
|
|
27
|
+
}
|
|
28
|
+
if (!AssetDatabase.IsValidFolder(channelFolderPath))
|
|
29
|
+
{
|
|
30
|
+
AssetDatabase.CreateFolder(questFolderPath, channelFolder);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
CreateQuestStartEventChannelFile(channelFolderPath, startQuestEventChannel);
|
|
34
|
+
CreateQuestProgressChannelFile(channelFolderPath, questProgressChannel);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static void CreateQuestStartEventChannelFile(string path, string startEventChannel)
|
|
38
|
+
{
|
|
39
|
+
if (File.Exists($"{path}/{startEventChannel}"))
|
|
40
|
+
{
|
|
41
|
+
Debug.Log($"file: [{path}/{startEventChannel}] was found.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Debug.Log($"file: [{path}/{startEventChannel}] not found. Creating it for you.");
|
|
46
|
+
StringEventChannelSO asset = ScriptableObject.CreateInstance<StringEventChannelSO>();
|
|
47
|
+
|
|
48
|
+
AssetDatabase.CreateAsset(asset, $"{path}/{startEventChannel}");
|
|
49
|
+
AssetDatabase.SaveAssets();
|
|
50
|
+
|
|
51
|
+
EditorUtility.FocusProjectWindow();
|
|
52
|
+
|
|
53
|
+
Selection.activeObject = asset;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static void CreateQuestProgressChannelFile(string path, string questProgressChannel)
|
|
57
|
+
{
|
|
58
|
+
if (File.Exists($"{path}/{questProgressChannel}"))
|
|
59
|
+
{
|
|
60
|
+
Debug.Log($"file: [{path}/{questProgressChannel}] was found.");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Debug.Log($"file: [{path}/{questProgressChannel}] not found. Creating it for you.");
|
|
65
|
+
StringFloatEventChannelSO asset = ScriptableObject.CreateInstance<StringFloatEventChannelSO>();
|
|
66
|
+
|
|
67
|
+
AssetDatabase.CreateAsset(asset, $"{path}/{questProgressChannel}");
|
|
68
|
+
AssetDatabase.SaveAssets();
|
|
69
|
+
|
|
70
|
+
EditorUtility.FocusProjectWindow();
|
|
71
|
+
|
|
72
|
+
Selection.activeObject = asset;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
#endif
|
|
76
|
+
}
|
package/Editor.meta
ADDED
|
@@ -444,7 +444,7 @@ MonoBehaviour:
|
|
|
444
444
|
m_Calls:
|
|
445
445
|
- m_Target: {fileID: 6366255227919844238}
|
|
446
446
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
447
|
-
m_MethodName:
|
|
447
|
+
m_MethodName: AllClear
|
|
448
448
|
m_Mode: 6
|
|
449
449
|
m_Arguments:
|
|
450
450
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -459,7 +459,7 @@ MonoBehaviour:
|
|
|
459
459
|
m_Calls:
|
|
460
460
|
- m_Target: {fileID: 6366255227919844238}
|
|
461
461
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
462
|
-
m_MethodName:
|
|
462
|
+
m_MethodName: AllClear
|
|
463
463
|
m_Mode: 6
|
|
464
464
|
m_Arguments:
|
|
465
465
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -549,7 +549,7 @@ MonoBehaviour:
|
|
|
549
549
|
m_Calls:
|
|
550
550
|
- m_Target: {fileID: 740138255012303216}
|
|
551
551
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
552
|
-
m_MethodName:
|
|
552
|
+
m_MethodName: AllClear
|
|
553
553
|
m_Mode: 6
|
|
554
554
|
m_Arguments:
|
|
555
555
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -564,7 +564,7 @@ MonoBehaviour:
|
|
|
564
564
|
m_Calls:
|
|
565
565
|
- m_Target: {fileID: 740138255012303216}
|
|
566
566
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
567
|
-
m_MethodName:
|
|
567
|
+
m_MethodName: AllClear
|
|
568
568
|
m_Mode: 6
|
|
569
569
|
m_Arguments:
|
|
570
570
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -129,7 +129,7 @@ MonoBehaviour:
|
|
|
129
129
|
m_Calls:
|
|
130
130
|
- m_Target: {fileID: 1059188078616771896}
|
|
131
131
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
132
|
-
m_MethodName:
|
|
132
|
+
m_MethodName: AllClear
|
|
133
133
|
m_Mode: 6
|
|
134
134
|
m_Arguments:
|
|
135
135
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -144,7 +144,7 @@ MonoBehaviour:
|
|
|
144
144
|
m_Calls:
|
|
145
145
|
- m_Target: {fileID: 1059188078616771896}
|
|
146
146
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
147
|
-
m_MethodName:
|
|
147
|
+
m_MethodName: AllClear
|
|
148
148
|
m_Mode: 6
|
|
149
149
|
m_Arguments:
|
|
150
150
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -1,115 +1,132 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections;
|
|
3
|
-
using System.Collections.Generic;
|
|
4
1
|
using jeanf.EventSystem;
|
|
5
2
|
using UnityEngine;
|
|
3
|
+
using UnityEngine.Serialization;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
namespace jeanf.questsystem
|
|
8
6
|
{
|
|
9
|
-
public
|
|
10
|
-
{
|
|
11
|
-
get => _isDebug;
|
|
12
|
-
set => _isDebug = value;
|
|
13
|
-
}
|
|
14
|
-
[SerializeField] private bool _isDebug = false;
|
|
15
|
-
|
|
16
|
-
[Tooltip("Visual feedback for the quest state")]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[Header("Quest")]
|
|
20
|
-
[SerializeField] private QuestInfoSO questInfoForPoint;
|
|
21
|
-
|
|
22
|
-
[ReadOnly] [Range(0,1)] [SerializeField] private float progress = 0.0f;
|
|
23
|
-
|
|
24
|
-
[Header("Config")]
|
|
25
|
-
[SerializeField] private bool startPoint = true;
|
|
26
|
-
[SerializeField] private bool finishPoint = true;
|
|
27
|
-
|
|
28
|
-
[SerializeField] [ReadOnly] private bool playerIsNear = false;
|
|
29
|
-
private string questId;
|
|
30
|
-
private QuestState currentQuestState;
|
|
31
|
-
|
|
32
|
-
// the event is Located in Assets/Resources/Quests/QuestsProgressChannel - it is searched for at Awake time.
|
|
33
|
-
private StringFloatEventChannelSO QuestProgress;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private void Awake()
|
|
7
|
+
public class QuestItem : MonoBehaviour, IDebugBehaviour
|
|
38
8
|
{
|
|
39
|
-
|
|
9
|
+
public bool isDebug
|
|
40
10
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if(QuestProgress == null) Debug.LogError("Quests/QuestsProgressChannel is not in the resources folder",this);
|
|
11
|
+
get => _isDebug;
|
|
12
|
+
set => _isDebug = value;
|
|
44
13
|
}
|
|
45
14
|
|
|
15
|
+
[SerializeField] private bool _isDebug = false;
|
|
46
16
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
questId = questInfoForPoint.id;
|
|
50
|
-
}
|
|
17
|
+
[Tooltip("Visual feedback for the quest state")] [Header("Quest")] [SerializeField]
|
|
18
|
+
private QuestInfoSO questInfoForPoint;
|
|
51
19
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
QuestProgress.OnEventRaised += UpdateProgress;
|
|
55
|
-
GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
|
|
56
|
-
GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
|
|
57
|
-
}
|
|
20
|
+
[ReadOnly] [Range(0, 1)] [SerializeField]
|
|
21
|
+
private float progress = 0.0f;
|
|
58
22
|
|
|
59
|
-
|
|
60
|
-
|
|
23
|
+
[FormerlySerializedAs("playerIsNear")] [SerializeField] [ReadOnly]
|
|
24
|
+
private bool clearToStart = false;
|
|
61
25
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
QuestProgress.OnEventRaised -= UpdateProgress;
|
|
65
|
-
GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
|
|
66
|
-
GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
|
|
67
|
-
}
|
|
26
|
+
private string questId;
|
|
27
|
+
private QuestState currentQuestState;
|
|
68
28
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
29
|
+
// these events are Located in Assets/Resources/Quests/Channels - it is searched for at Awake time.
|
|
30
|
+
// if they do not exist simply right click in the hierarchy and find >InitializeQuestSystem<
|
|
31
|
+
private StringFloatEventChannelSO QuestProgress;
|
|
32
|
+
private StringEventChannelSO StartQuestEventChannel;
|
|
33
|
+
|
|
34
|
+
public void OnValidate()
|
|
73
35
|
{
|
|
74
|
-
|
|
36
|
+
const string searching = "attempting to find";
|
|
37
|
+
const string _ = "Quests/Channels"; // search target
|
|
38
|
+
const string searchLocation = "the resources folder";
|
|
39
|
+
const string readInstructions = "please read the package instruction for further help";
|
|
40
|
+
|
|
41
|
+
if (QuestProgress == null)
|
|
42
|
+
{
|
|
43
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestsProgressChannel in {searchLocation} ", this);
|
|
44
|
+
QuestProgress = Resources.Load<StringFloatEventChannelSO>($"{_}/QuestsProgressChannel");
|
|
45
|
+
if (QuestProgress == null)
|
|
46
|
+
Debug.LogError($"{_}/QuestsProgressChannel is not in {searchLocation} {readInstructions}", this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (StartQuestEventChannel == null)
|
|
50
|
+
{
|
|
51
|
+
if (isDebug) Debug.Log($"{searching} {_}/StartQuestEventChannel in {searchLocation}", this);
|
|
52
|
+
StartQuestEventChannel = Resources.Load<StringEventChannelSO>($"{_}/StartQuestEventChannel");
|
|
53
|
+
if (QuestProgress == null)
|
|
54
|
+
Debug.LogError($"{_}/StartQuestEventChannel is not {searchLocation} {readInstructions}", this);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
questId = questInfoForPoint.id;
|
|
75
58
|
}
|
|
76
|
-
if (isDebug) Debug.Log($"Player is near, continuing ...");
|
|
77
59
|
|
|
78
|
-
|
|
79
|
-
if (currentQuestState.Equals(QuestState.CAN_START) && startPoint)
|
|
60
|
+
private void OnEnable()
|
|
80
61
|
{
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
StartQuestEventChannel.OnEventRaised += RequestQuestStart;
|
|
63
|
+
QuestProgress.OnEventRaised += UpdateProgress;
|
|
64
|
+
GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
|
|
65
|
+
GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
|
|
83
66
|
}
|
|
84
|
-
|
|
67
|
+
|
|
68
|
+
private void OnDisable() => Unsubscribe();
|
|
69
|
+
private void OnDestroy() => Unsubscribe();
|
|
70
|
+
|
|
71
|
+
private void Unsubscribe()
|
|
85
72
|
{
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
StartQuestEventChannel.OnEventRaised -= RequestQuestStart;
|
|
74
|
+
QuestProgress.OnEventRaised -= UpdateProgress;
|
|
75
|
+
GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
|
|
76
|
+
GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
|
|
88
77
|
}
|
|
89
|
-
}
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
if (id == questId)
|
|
79
|
+
public void UpdateState()
|
|
94
80
|
{
|
|
95
|
-
|
|
96
|
-
if
|
|
81
|
+
if (isDebug) Debug.Log($"Updating State...");
|
|
82
|
+
if (!clearToStart)
|
|
83
|
+
{
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isDebug) Debug.Log($"All is clear, continuing ...");
|
|
88
|
+
|
|
89
|
+
// start or finish a quest
|
|
90
|
+
if (currentQuestState.Equals(QuestState.CAN_START))
|
|
91
|
+
{
|
|
92
|
+
if (isDebug) Debug.Log($"Starting quest: {questId}");
|
|
93
|
+
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
94
|
+
}
|
|
95
|
+
else if (currentQuestState.Equals(QuestState.CAN_FINISH))
|
|
96
|
+
{
|
|
97
|
+
if (isDebug) Debug.Log($"Finishing quest: {questId}");
|
|
98
|
+
GameEventsManager.instance.questEvents.FinishQuest(questId);
|
|
99
|
+
}
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
private void UpdateProgress(string id, float progress)
|
|
103
|
+
{
|
|
104
|
+
if (id == questId)
|
|
105
|
+
{
|
|
106
|
+
this.progress = progress;
|
|
107
|
+
if (isDebug) Debug.Log($"questid [{id}] progress = {progress * 100}%");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
// only update the quest state if this point has the corresponding quest
|
|
104
|
-
if (quest.info.id.Equals(questId))
|
|
111
|
+
private void QuestStateChange(Quest quest)
|
|
105
112
|
{
|
|
106
|
-
|
|
113
|
+
// only update the quest state if this point has the corresponding quest
|
|
114
|
+
if (quest.info.id.Equals(questId))
|
|
115
|
+
{
|
|
116
|
+
currentQuestState = quest.state;
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
|
-
}
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
public void AllClear(bool value)
|
|
121
|
+
{
|
|
122
|
+
clearToStart = value;
|
|
123
|
+
UpdateState();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public void RequestQuestStart(string id)
|
|
127
|
+
{
|
|
128
|
+
if(id!= questId) return;
|
|
129
|
+
AllClear(true);
|
|
130
|
+
}
|
|
114
131
|
}
|
|
115
|
-
}
|
|
132
|
+
}
|
|
@@ -444,7 +444,7 @@ MonoBehaviour:
|
|
|
444
444
|
m_Calls:
|
|
445
445
|
- m_Target: {fileID: 6366255227919844238}
|
|
446
446
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
447
|
-
m_MethodName:
|
|
447
|
+
m_MethodName: AllClear
|
|
448
448
|
m_Mode: 6
|
|
449
449
|
m_Arguments:
|
|
450
450
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -459,7 +459,7 @@ MonoBehaviour:
|
|
|
459
459
|
m_Calls:
|
|
460
460
|
- m_Target: {fileID: 6366255227919844238}
|
|
461
461
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
462
|
-
m_MethodName:
|
|
462
|
+
m_MethodName: AllClear
|
|
463
463
|
m_Mode: 6
|
|
464
464
|
m_Arguments:
|
|
465
465
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -549,7 +549,7 @@ MonoBehaviour:
|
|
|
549
549
|
m_Calls:
|
|
550
550
|
- m_Target: {fileID: 740138255012303216}
|
|
551
551
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
552
|
-
m_MethodName:
|
|
552
|
+
m_MethodName: AllClear
|
|
553
553
|
m_Mode: 6
|
|
554
554
|
m_Arguments:
|
|
555
555
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -564,7 +564,7 @@ MonoBehaviour:
|
|
|
564
564
|
m_Calls:
|
|
565
565
|
- m_Target: {fileID: 740138255012303216}
|
|
566
566
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
567
|
-
m_MethodName:
|
|
567
|
+
m_MethodName: AllClear
|
|
568
568
|
m_Mode: 6
|
|
569
569
|
m_Arguments:
|
|
570
570
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -129,7 +129,7 @@ MonoBehaviour:
|
|
|
129
129
|
m_Calls:
|
|
130
130
|
- m_Target: {fileID: 1059188078616771896}
|
|
131
131
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
132
|
-
m_MethodName:
|
|
132
|
+
m_MethodName: AllClear
|
|
133
133
|
m_Mode: 6
|
|
134
134
|
m_Arguments:
|
|
135
135
|
m_ObjectArgument: {fileID: 0}
|
|
@@ -144,7 +144,7 @@ MonoBehaviour:
|
|
|
144
144
|
m_Calls:
|
|
145
145
|
- m_Target: {fileID: 1059188078616771896}
|
|
146
146
|
m_TargetAssemblyTypeName: QuestPoint, Assembly-CSharp
|
|
147
|
-
m_MethodName:
|
|
147
|
+
m_MethodName: AllClear
|
|
148
148
|
m_Mode: 6
|
|
149
149
|
m_Arguments:
|
|
150
150
|
m_ObjectArgument: {fileID: 0}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name":"fr.jeanf.questsystem",
|
|
3
|
-
"version":"0.0.
|
|
3
|
+
"version":"0.0.3",
|
|
4
4
|
"displayName":"Quest system",
|
|
5
5
|
"description":"This package uses Scriptable Objects to define quests.",
|
|
6
6
|
"unity": "2021.3",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"url":"https://jeanfrancoisrobin.art"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"fr.jeanf.propertydrawer": "1.1.1"
|
|
17
18
|
},
|
|
18
19
|
"samples": [
|
|
19
20
|
|