fr.jeanf.questsystem 0.0.1 → 0.0.2

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.
@@ -0,0 +1,74 @@
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
+ [MenuItem("GameObject/Initialize Quest System")]
11
+ private static void initializeQuestSystem()
12
+ {
13
+ var folder = "Quests";
14
+ var questFolderPath = $"Assets/Resources/{folder}";
15
+
16
+ var channelFolder = "Channels";
17
+ var channelFolderPath = $"{questFolderPath}/{channelFolder}";
18
+
19
+ // files needed
20
+ var questProgressChannel = $"QuestsProgressChannel.asset";
21
+ var startQuestEventChannel = $"StartQuestEventChannel.asset";
22
+
23
+ if (!AssetDatabase.IsValidFolder(questFolderPath))
24
+ {
25
+ AssetDatabase.CreateFolder("Assets/Resources", folder);
26
+ }
27
+ if (!AssetDatabase.IsValidFolder(channelFolderPath))
28
+ {
29
+ AssetDatabase.CreateFolder(questFolderPath, channelFolder);
30
+ }
31
+
32
+ CreateQuestStartEventChannelFile(channelFolderPath, startQuestEventChannel);
33
+ CreateQuestProgressChannelFile(channelFolderPath, questProgressChannel);
34
+ }
35
+
36
+ public static void CreateQuestStartEventChannelFile(string path, string startEventChannel)
37
+ {
38
+ if (File.Exists($"{path}/{startEventChannel}"))
39
+ {
40
+ Debug.Log($"file: [{path}/{startEventChannel}] was found.");
41
+ return;
42
+ }
43
+
44
+ Debug.Log($"file: [{path}/{startEventChannel}] not found. Creating it for you.");
45
+ StringEventChannelSO asset = ScriptableObject.CreateInstance<StringEventChannelSO>();
46
+
47
+ AssetDatabase.CreateAsset(asset, $"{path}/{startEventChannel}");
48
+ AssetDatabase.SaveAssets();
49
+
50
+ EditorUtility.FocusProjectWindow();
51
+
52
+ Selection.activeObject = asset;
53
+ }
54
+
55
+ public static void CreateQuestProgressChannelFile(string path, string questProgressChannel)
56
+ {
57
+ if (File.Exists($"{path}/{questProgressChannel}"))
58
+ {
59
+ Debug.Log($"file: [{path}/{questProgressChannel}] was found.");
60
+ return;
61
+ }
62
+
63
+ Debug.Log($"file: [{path}/{questProgressChannel}] not found. Creating it for you.");
64
+ StringFloatEventChannelSO asset = ScriptableObject.CreateInstance<StringFloatEventChannelSO>();
65
+
66
+ AssetDatabase.CreateAsset(asset, $"{path}/{questProgressChannel}");
67
+ AssetDatabase.SaveAssets();
68
+
69
+ EditorUtility.FocusProjectWindow();
70
+
71
+ Selection.activeObject = asset;
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 3d2c56c7fb5108442a42778a7637bce6
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
package/Editor.meta ADDED
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 097a66bf264d7704bbd95257cce71f41
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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
- public class QuestItem : MonoBehaviour, IDebugBehaviour
5
+ namespace jeanf.questsystem
8
6
  {
9
- public bool isDebug
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
- if (QuestProgress == null)
9
+ public bool isDebug
40
10
  {
41
- if(isDebug) Debug.Log("attempting to find Quests/QuestsProgressChannel in the resources folder" ,this);
42
- QuestProgress = Resources.Load<StringFloatEventChannelSO>("Quests/QuestsProgressChannel");
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
- var questIconPrefab = Instantiate(Resources.Load<GameObject>("Quests/QuestIcon"), this.transform);
48
-
49
- questId = questInfoForPoint.id;
50
- }
17
+ [Tooltip("Visual feedback for the quest state")] [Header("Quest")] [SerializeField]
18
+ private QuestInfoSO questInfoForPoint;
51
19
 
52
- private void OnEnable()
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
- private void OnDisable() => Unsubscribe();
60
- private void OnDestroy() => Unsubscribe();
23
+ [FormerlySerializedAs("playerIsNear")] [SerializeField] [ReadOnly]
24
+ private bool clearToStart = false;
61
25
 
62
- private void Unsubscribe()
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
- public void UpdateState()
70
- {
71
- if (isDebug) Debug.Log($"Updating State...");
72
- if (!playerIsNear)
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
- return;
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
- // start or finish a quest
79
- if (currentQuestState.Equals(QuestState.CAN_START) && startPoint)
60
+ private void OnEnable()
80
61
  {
81
- if(isDebug) Debug.Log($"Starting quest: {questId}");
82
- GameEventsManager.instance.questEvents.StartQuest(questId);
62
+ StartQuestEventChannel.OnEventRaised += RequestQuestStart;
63
+ QuestProgress.OnEventRaised += UpdateProgress;
64
+ GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
65
+ GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
83
66
  }
84
- else if (currentQuestState.Equals(QuestState.CAN_FINISH) && finishPoint)
67
+
68
+ private void OnDisable() => Unsubscribe();
69
+ private void OnDestroy() => Unsubscribe();
70
+
71
+ private void Unsubscribe()
85
72
  {
86
- if(isDebug) Debug.Log($"Finishing quest: {questId}");
87
- GameEventsManager.instance.questEvents.FinishQuest(questId);
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
- private void UpdateProgress(string id, float progress)
92
- {
93
- if (id == questId)
79
+ public void UpdateState()
94
80
  {
95
- this.progress = progress;
96
- if(isDebug) Debug.Log($"questid [{id}] progress = {progress*100}%");
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
- private void QuestStateChange(Quest quest)
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
- currentQuestState = quest.state;
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
- public void PlayerIsNear(bool value)
111
- {
112
- playerIsNear = value;
113
- UpdateState();
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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: PlayerIsNear
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.1",
3
+ "version":"0.0.2",
4
4
  "displayName":"Quest system",
5
5
  "description":"This package uses Scriptable Objects to define quests.",
6
6
  "unity": "2021.3",