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
|
@@ -2,100 +2,107 @@ using System.Collections;
|
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using UnityEngine;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
namespace jeanf.questsystem
|
|
6
6
|
{
|
|
7
|
-
|
|
8
|
-
public QuestInfoSO info;
|
|
9
|
-
|
|
10
|
-
// state info
|
|
11
|
-
public QuestState state;
|
|
12
|
-
private int currentQuestStepIndex;
|
|
13
|
-
public int currentStep;
|
|
14
|
-
private QuestStepState[] questStepStates;
|
|
15
|
-
|
|
16
|
-
public Quest(QuestInfoSO questInfo)
|
|
7
|
+
public class Quest
|
|
17
8
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.currentQuestStepIndex = currentStep = 0;
|
|
21
|
-
this.questStepStates = new QuestStepState[info.questStepPrefabs.Length];
|
|
22
|
-
for (int i = 0; i < questStepStates.Length; i++)
|
|
23
|
-
{
|
|
24
|
-
questStepStates[i] = new QuestStepState();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
9
|
+
// static info
|
|
10
|
+
public QuestInfoSO info;
|
|
27
11
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
currentStep = this.currentQuestStepIndex;
|
|
34
|
-
this.questStepStates = questStepStates;
|
|
12
|
+
// state info
|
|
13
|
+
public QuestState state;
|
|
14
|
+
private int currentQuestStepIndex;
|
|
15
|
+
public int currentStep;
|
|
16
|
+
private QuestStepState[] questStepStates;
|
|
35
17
|
|
|
36
|
-
|
|
37
|
-
// something has changed during development and the saved data is out of sync.
|
|
38
|
-
if (this.questStepStates.Length != this.info.questStepPrefabs.Length)
|
|
18
|
+
public Quest(QuestInfoSO questInfo)
|
|
39
19
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
this.info = questInfo;
|
|
21
|
+
this.state = QuestState.REQUIREMENTS_NOT_MET;
|
|
22
|
+
this.currentQuestStepIndex = currentStep = 0;
|
|
23
|
+
this.questStepStates = new QuestStepState[info.questStepPrefabs.Length];
|
|
24
|
+
for (int i = 0; i < questStepStates.Length; i++)
|
|
25
|
+
{
|
|
26
|
+
questStepStates[i] = new QuestStepState();
|
|
27
|
+
}
|
|
44
28
|
}
|
|
45
|
-
}
|
|
46
29
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
public Quest(QuestInfoSO questInfo, QuestState questState, int currentQuestStepIndex,
|
|
31
|
+
QuestStepState[] questStepStates)
|
|
32
|
+
{
|
|
33
|
+
this.info = questInfo;
|
|
34
|
+
this.state = questState;
|
|
35
|
+
this.currentQuestStepIndex = currentQuestStepIndex;
|
|
36
|
+
currentStep = this.currentQuestStepIndex;
|
|
37
|
+
this.questStepStates = questStepStates;
|
|
52
38
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
// if the quest step states and prefabs are different lengths,
|
|
40
|
+
// something has changed during development and the saved data is out of sync.
|
|
41
|
+
if (this.questStepStates.Length != this.info.questStepPrefabs.Length)
|
|
42
|
+
{
|
|
43
|
+
Debug.LogWarning("Quest Step Prefabs and Quest Step States are "
|
|
44
|
+
+ "of different lengths. This indicates something changed "
|
|
45
|
+
+ "with the QuestInfo and the saved data is now out of sync. "
|
|
46
|
+
+ "Reset your data - as this might cause issues. QuestId: " + this.info.id);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
GameObject questStepPrefab = GetCurrentQuestStepPrefab();
|
|
61
|
-
if (questStepPrefab != null)
|
|
50
|
+
public void MoveToNextStep()
|
|
62
51
|
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
questStep.InitializeQuestStep(info.id, currentQuestStepIndex, questStepStates[currentQuestStepIndex].state);
|
|
52
|
+
currentQuestStepIndex++;
|
|
53
|
+
currentStep = currentQuestStepIndex;
|
|
66
54
|
}
|
|
67
|
-
}
|
|
68
55
|
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
GameObject questStepPrefab = null;
|
|
72
|
-
if (CurrentStepExists())
|
|
56
|
+
public bool CurrentStepExists()
|
|
73
57
|
{
|
|
74
|
-
|
|
58
|
+
return (currentQuestStepIndex < info.questStepPrefabs.Length);
|
|
75
59
|
}
|
|
76
|
-
|
|
60
|
+
|
|
61
|
+
public void InstantiateCurrentQuestStep(Transform parentTransform)
|
|
77
62
|
{
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
GameObject questStepPrefab = GetCurrentQuestStepPrefab();
|
|
64
|
+
if (questStepPrefab != null)
|
|
65
|
+
{
|
|
66
|
+
QuestStep questStep = Object.Instantiate<GameObject>(questStepPrefab, parentTransform)
|
|
67
|
+
.GetComponent<QuestStep>();
|
|
68
|
+
questStep.InitializeQuestStep(info.id, currentQuestStepIndex,
|
|
69
|
+
questStepStates[currentQuestStepIndex].state);
|
|
70
|
+
}
|
|
80
71
|
}
|
|
81
|
-
return questStepPrefab;
|
|
82
|
-
}
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
if (stepIndex < questStepStates.Length)
|
|
73
|
+
private GameObject GetCurrentQuestStepPrefab()
|
|
87
74
|
{
|
|
88
|
-
|
|
75
|
+
GameObject questStepPrefab = null;
|
|
76
|
+
if (CurrentStepExists())
|
|
77
|
+
{
|
|
78
|
+
questStepPrefab = info.questStepPrefabs[currentQuestStepIndex];
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
Debug.LogWarning("Tried to get quest step prefab, but stepIndex was out of range indicating that "
|
|
83
|
+
+ "there's no current step: QuestId=" + info.id + ", stepIndex=" +
|
|
84
|
+
currentQuestStepIndex);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return questStepPrefab;
|
|
89
88
|
}
|
|
90
|
-
|
|
89
|
+
|
|
90
|
+
public void StoreQuestStepState(QuestStepState questStepState, int stepIndex)
|
|
91
91
|
{
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
if (stepIndex < questStepStates.Length)
|
|
93
|
+
{
|
|
94
|
+
questStepStates[stepIndex].state = questStepState.state;
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
{
|
|
98
|
+
Debug.LogWarning("Tried to access quest step data, but stepIndex was out of range: "
|
|
99
|
+
+ "Quest Id = " + info.id + ", Step Index = " + stepIndex);
|
|
100
|
+
}
|
|
94
101
|
}
|
|
95
|
-
}
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
public QuestData GetQuestData()
|
|
104
|
+
{
|
|
105
|
+
return new QuestData(state, currentQuestStepIndex, questStepStates);
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
|
-
}
|
|
108
|
+
}
|
|
@@ -2,17 +2,20 @@ using System.Collections;
|
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using UnityEngine;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
public class QuestData
|
|
5
|
+
namespace jeanf.questsystem
|
|
7
6
|
{
|
|
8
|
-
|
|
9
|
-
public
|
|
10
|
-
public QuestStepState[] questStepStates;
|
|
11
|
-
|
|
12
|
-
public QuestData(QuestState state, int questStepIndex, QuestStepState[] questStepStates)
|
|
7
|
+
[System.Serializable]
|
|
8
|
+
public class QuestData
|
|
13
9
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
public QuestState state;
|
|
11
|
+
public int questStepIndex;
|
|
12
|
+
public QuestStepState[] questStepStates;
|
|
13
|
+
|
|
14
|
+
public QuestData(QuestState state, int questStepIndex, QuestStepState[] questStepStates)
|
|
15
|
+
{
|
|
16
|
+
this.state = state;
|
|
17
|
+
this.questStepIndex = questStepIndex;
|
|
18
|
+
this.questStepStates = questStepStates;
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
|
-
}
|
|
21
|
+
}
|
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
using System.Collections;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using UnityEngine;
|
|
4
|
+
using jeanf.propertyDrawer;
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
namespace jeanf.questsystem
|
|
7
|
+
{
|
|
8
|
+
[CreateAssetMenu(fileName = "QuestInfoSO", menuName = "Quests/QuestInfoSO", order = 1)]
|
|
9
|
+
[ScriptableObjectDrawer]
|
|
10
|
+
public class QuestInfoSO : ScriptableObject
|
|
11
|
+
{
|
|
12
|
+
[field: SerializeField] public string id { get; private set; }
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
public string displayName;
|
|
14
|
+
[Header("General")] public string displayName;
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
public QuestInfoSO[] questPrerequisites;
|
|
16
|
+
[Header("Requirements")] public int levelRequirement;
|
|
17
|
+
public QuestInfoSO[] questPrerequisites;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
public GameObject[] questStepPrefabs;
|
|
19
|
+
[Header("Steps")] public GameObject[] questStepPrefabs;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// ensure the id is always the name of the Scriptable Object asset
|
|
25
|
-
private void OnValidate()
|
|
26
|
-
{
|
|
27
|
-
/*
|
|
28
|
-
#if UNITY_EDITOR
|
|
29
|
-
if (id == string.Empty) id = this.name;
|
|
30
|
-
if (this != null) UnityEditor.EditorUtility.SetDirty(this);
|
|
31
|
-
#endif
|
|
32
|
-
*/
|
|
33
|
-
}
|
|
34
|
-
}
|
|
21
|
+
[Header("Rewards")] public string unlockedScenario;
|
|
22
|
+
}
|
|
23
|
+
}
|