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