net.dreditor.minigames.mc 0.1.6 → 0.1.8

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.
@@ -1,296 +1,296 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using DREditor.Audio;
3
- using DREditor.Services;
4
- using DREditor.UIHandling;
5
- using System.Collections;
6
- using System.Collections.Generic;
7
- using TMPro;
8
- using UnityEngine;
9
- using UnityEngine.Events;
10
- using UnityEngine.EventSystems;
11
- using UnityEngine.InputSystem;
12
- using UnityEngine.UI;
13
- using static UnityEngine.InputSystem.InputAction;
14
-
15
- namespace DREditor.Minigames.MC
16
- {
17
- /// <summary>
18
- ///
19
- /// </summary>
20
- [ClassHeader(nameof(MinigameManagerBase) + ", " +
21
- "\n\n")]
22
- public class MultipleChoiceManager : MinigameManagerBase
23
- {
24
- /// <summary>
25
- ///
26
- /// </summary>
27
- [Tooltip("")]
28
- [SerializeField] protected InputActionReference submit = null;
29
-
30
-
31
- /// <summary>
32
- ///
33
- /// </summary>
34
- [Header("")]
35
- [Divider]
36
- [Tooltip("")]
37
- [SerializeField] protected bool debugMode = false;
38
-
39
- /// <summary>
40
- ///
41
- /// </summary>
42
- [Tooltip("")]
43
- [SerializeField] protected MultipleChoiceBuilder builder = null;
44
-
45
-
46
- /// <summary>
47
- ///
48
- /// </summary>
49
- [Header("")]
50
- [Divider]
51
- [Tooltip("")]
52
- [SerializeField] protected TMP_Text questionText = null;
53
-
54
- /// <summary>
55
- ///
56
- /// </summary>
57
- [Tooltip("")]
58
- [SerializeField] protected Transform choicesParent = null;
59
-
60
- /// <summary>
61
- ///
62
- /// </summary>
63
- [Tooltip("")]
64
- [SerializeField] protected GameObject choicePrefab = null;
65
-
66
- /// <summary>
67
- ///
68
- /// </summary>
69
- [Tooltip("")]
70
- [SerializeField] protected UIVisibilityComponent gameUI = null;
71
-
72
- /// <summary>
73
- ///
74
- /// </summary>
75
- [Tooltip("")]
76
- [SerializeField] protected UIVisibilityComponent introUI = null;
77
-
78
- /// <summary>
79
- ///
80
- /// </summary>
81
- [Tooltip("")]
82
- [SerializeField] protected UIVisibilityComponent answerUI = null;
83
-
84
- /// <summary>
85
- ///
86
- /// </summary>
87
- [Tooltip("")]
88
- [SerializeField] protected float menuFadeWaitTime = 0.75f;
89
-
90
-
91
- [Header("")]
92
- [SerializeField] protected UnityEvent OnMinigameStarted;
93
-
94
-
95
- /// <summary>
96
- ///
97
- /// </summary>
98
- protected bool inSelect = false;
99
-
100
- /// <summary>
101
- ///
102
- /// </summary>
103
- protected List<Selectable> choices = new();
104
-
105
-
106
- /// <summary>
107
- ///
108
- /// </summary>
109
- /// <param name="inSelect"></param>
110
- protected virtual void SetInSelect(bool inSelect) => this.inSelect = inSelect;
111
-
112
-
113
- /// <inheritdoc/>
114
- protected override void OnMinigameDisable()
115
- {
116
- base.OnMinigameDisable();
117
-
118
- submit.action.started -= SubmitChoice;
119
- }
120
-
121
- /// <summary>
122
- ///
123
- /// </summary>
124
- protected virtual void Start()
125
- {
126
- if (debugMode)
127
- StartChoosing(builder);
128
- }
129
-
130
- /// <summary>
131
- ///
132
- /// </summary>
133
- /// <param name="asset"></param>
134
- public void PlayMultipleChoice(ScriptableObject asset)
135
- => FindAnyObjectByType<MultipleChoiceManager>().StartChoosing((MultipleChoiceBuilder)asset);
136
-
137
- /// <summary>
138
- ///
139
- /// </summary>
140
- /// <param name="builder"></param>
141
- public virtual void StartChoosing(MultipleChoiceBuilder builder) => StartCoroutine(BeginChoice(builder));
142
-
143
- /// <summary>
144
- ///
145
- /// </summary>
146
- protected virtual IEnumerator BeginChoice(MultipleChoiceBuilder builder)
147
- {
148
- this.builder = builder;
149
-
150
- Initialize();
151
-
152
- if (questionText != null)
153
- questionText.text = builder.question;
154
-
155
- OnMinigameStarted?.Invoke();
156
-
157
- if (introUI != null)
158
- yield return introUI.ShowTillComplete();
159
-
160
- if (TrialTimer != null)
161
- TrialTimer.ShowInitialize(builder.times, false);
162
-
163
- EventSystem.current.SetSelectedGameObject(choices[0].gameObject);
164
-
165
- submit.action.started += SubmitChoice;
166
-
167
- SetInSelect(true);
168
-
169
- yield break;
170
- }
171
-
172
- /// <summary>
173
- ///
174
- /// </summary>
175
- protected virtual void Initialize()
176
- {
177
- var choiceTexts = builder.GetChoiceTexts();
178
-
179
- foreach (var choiceText in choiceTexts)
180
- {
181
- if (string.IsNullOrEmpty(choiceText))
182
- continue;
183
-
184
- GameObject choice = Instantiate(choicePrefab, choicesParent);
185
-
186
- choice.GetComponentInChildren<TMP_Text>().text = choiceText;
187
-
188
- choices.Add(choice.GetComponent<Selectable>());
189
- }
190
- }
191
-
192
- /// <summary>
193
- ///
194
- /// </summary>
195
- /// <param name="context"></param>
196
- protected virtual void SubmitChoice(CallbackContext context)
197
- {
198
- if (inSelect)
199
- {
200
- string selectedText = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TMP_Text>().text;
201
-
202
- MultipleChoiceOption selectedOption = builder.GetOptionWithText(selectedText);
203
-
204
- if (selectedOption == null)
205
- return;
206
-
207
- ServiceLocator.GetService<SFXManagerBase>().PlaySubmit();
208
-
209
- SetInSelect(false);
210
-
211
- submit.action.started -= SubmitChoice;
212
-
213
- EventSystem.current.SetSelectedGameObject(null);
214
-
215
- if (TrialTimer != null)
216
- TrialTimer.PauseTimer();
217
-
218
- HideVisuals();
219
-
220
- if (selectedOption.isAnswer)
221
- StartCoroutine(ResolveMinigame());
222
- else
223
- TrialMistake(selectedOption.wrongDialogue);
224
- }
225
- }
226
-
227
- /// <inheritdoc/>
228
- public override IEnumerator ResolveMinigame()
229
- {
230
- yield return new WaitForSeconds(menuFadeWaitTime);
231
-
232
- if (answerUI != null)
233
- yield return answerUI.ShowTillComplete();
234
-
235
- yield return base.ResolveMinigame();
236
-
237
- yield break;
238
- }
239
-
240
- /// <summary>
241
- ///
242
- /// </summary>
243
- protected virtual void HideVisuals()
244
- {
245
- if (TrialTimer != null)
246
- TrialTimer.Hide();
247
-
248
- gameUI.Hide();
249
- }
250
-
251
- /// <inheritdoc/>
252
- protected override void Restart()
253
- {
254
- gameUI.Show();
255
-
256
- EventSystem.current.SetSelectedGameObject(choices[0].gameObject);
257
-
258
- if (TrialTimer != null)
259
- TrialTimer.Show();
260
-
261
- StartCoroutine(ResolveRestart());
262
- }
263
-
264
- /// <summary>
265
- ///
266
- /// </summary>
267
- protected virtual IEnumerator ResolveRestart()
268
- {
269
- yield return TrialTimer.WaitForChangeToComplete();
270
-
271
- if (TrialTimer != null)
272
- TrialTimer.ResumeTimer();
273
-
274
- yield return new WaitForSeconds(Time.deltaTime);
275
-
276
- submit.action.started += SubmitChoice;
277
-
278
- SetInSelect(true);
279
-
280
- yield break;
281
- }
282
-
283
-
284
- /// <inheritdoc/>
285
- protected override void OnTimeUp()
286
- {
287
- SetInSelect(false);
288
-
289
- EventSystem.current.SetSelectedGameObject(null);
290
-
291
- HideVisuals();
292
-
293
- base.OnTimeUp();
294
- }
295
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Audio;
3
+ using DREditor.Services;
4
+ using DREditor.UIHandling;
5
+ using System.Collections;
6
+ using System.Collections.Generic;
7
+ using TMPro;
8
+ using UnityEngine;
9
+ using UnityEngine.Events;
10
+ using UnityEngine.EventSystems;
11
+ using UnityEngine.InputSystem;
12
+ using UnityEngine.UI;
13
+ using static UnityEngine.InputSystem.InputAction;
14
+
15
+ namespace DREditor.Minigames.MC
16
+ {
17
+ /// <summary>
18
+ ///
19
+ /// </summary>
20
+ [ClassHeader(nameof(MinigameManagerBase) + ", " +
21
+ "\n\n")]
22
+ public class MultipleChoiceManager : MinigameManagerBase
23
+ {
24
+ /// <summary>
25
+ ///
26
+ /// </summary>
27
+ [Tooltip("")]
28
+ [SerializeField] protected InputActionReference submit = null;
29
+
30
+
31
+ /// <summary>
32
+ ///
33
+ /// </summary>
34
+ [Header("")]
35
+ [Divider]
36
+ [Tooltip("")]
37
+ [SerializeField] protected bool debugMode = false;
38
+
39
+ /// <summary>
40
+ ///
41
+ /// </summary>
42
+ [Tooltip("")]
43
+ [SerializeField] protected MultipleChoiceBuilder builder = null;
44
+
45
+
46
+ /// <summary>
47
+ ///
48
+ /// </summary>
49
+ [Header("")]
50
+ [Divider]
51
+ [Tooltip("")]
52
+ [SerializeField] protected TMP_Text questionText = null;
53
+
54
+ /// <summary>
55
+ ///
56
+ /// </summary>
57
+ [Tooltip("")]
58
+ [SerializeField] protected Transform choicesParent = null;
59
+
60
+ /// <summary>
61
+ ///
62
+ /// </summary>
63
+ [Tooltip("")]
64
+ [SerializeField] protected GameObject choicePrefab = null;
65
+
66
+ /// <summary>
67
+ ///
68
+ /// </summary>
69
+ [Tooltip("")]
70
+ [SerializeField] protected UIVisibilityComponent gameUI = null;
71
+
72
+ /// <summary>
73
+ ///
74
+ /// </summary>
75
+ [Tooltip("")]
76
+ [SerializeField] protected UIVisibilityComponent introUI = null;
77
+
78
+ /// <summary>
79
+ ///
80
+ /// </summary>
81
+ [Tooltip("")]
82
+ [SerializeField] protected UIVisibilityComponent answerUI = null;
83
+
84
+ /// <summary>
85
+ ///
86
+ /// </summary>
87
+ [Tooltip("")]
88
+ [SerializeField] protected float menuFadeWaitTime = 0.75f;
89
+
90
+
91
+ [Header("")]
92
+ [SerializeField] protected UnityEvent OnMinigameStarted;
93
+
94
+
95
+ /// <summary>
96
+ ///
97
+ /// </summary>
98
+ protected bool inSelect = false;
99
+
100
+ /// <summary>
101
+ ///
102
+ /// </summary>
103
+ protected List<Selectable> choices = new();
104
+
105
+
106
+ /// <summary>
107
+ ///
108
+ /// </summary>
109
+ /// <param name="inSelect"></param>
110
+ protected virtual void SetInSelect(bool inSelect) => this.inSelect = inSelect;
111
+
112
+
113
+ /// <inheritdoc/>
114
+ protected override void OnMinigameDisable()
115
+ {
116
+ base.OnMinigameDisable();
117
+
118
+ submit.action.started -= SubmitChoice;
119
+ }
120
+
121
+ /// <summary>
122
+ ///
123
+ /// </summary>
124
+ protected virtual void Start()
125
+ {
126
+ if (debugMode)
127
+ StartChoosing(builder);
128
+ }
129
+
130
+ /// <summary>
131
+ ///
132
+ /// </summary>
133
+ /// <param name="asset"></param>
134
+ public void PlayMultipleChoice(ScriptableObject asset)
135
+ => FindAnyObjectByType<MultipleChoiceManager>().StartChoosing((MultipleChoiceBuilder)asset);
136
+
137
+ /// <summary>
138
+ ///
139
+ /// </summary>
140
+ /// <param name="builder"></param>
141
+ public virtual void StartChoosing(MultipleChoiceBuilder builder) => StartCoroutine(BeginChoice(builder));
142
+
143
+ /// <summary>
144
+ ///
145
+ /// </summary>
146
+ protected virtual IEnumerator BeginChoice(MultipleChoiceBuilder builder)
147
+ {
148
+ this.builder = builder;
149
+
150
+ Initialize();
151
+
152
+ if (questionText != null)
153
+ questionText.text = builder.question;
154
+
155
+ OnMinigameStarted?.Invoke();
156
+
157
+ if (introUI != null)
158
+ yield return introUI.ShowTillComplete();
159
+
160
+ if (TrialTimer != null)
161
+ TrialTimer.ShowInitialize(builder.times, false);
162
+
163
+ EventSystem.current.SetSelectedGameObject(choices[0].gameObject);
164
+
165
+ submit.action.started += SubmitChoice;
166
+
167
+ SetInSelect(true);
168
+
169
+ yield break;
170
+ }
171
+
172
+ /// <summary>
173
+ ///
174
+ /// </summary>
175
+ protected virtual void Initialize()
176
+ {
177
+ var choiceTexts = builder.GetChoiceTexts();
178
+
179
+ foreach (var choiceText in choiceTexts)
180
+ {
181
+ if (string.IsNullOrEmpty(choiceText))
182
+ continue;
183
+
184
+ GameObject choice = Instantiate(choicePrefab, choicesParent);
185
+
186
+ choice.GetComponentInChildren<TMP_Text>().text = choiceText;
187
+
188
+ choices.Add(choice.GetComponent<Selectable>());
189
+ }
190
+ }
191
+
192
+ /// <summary>
193
+ ///
194
+ /// </summary>
195
+ /// <param name="context"></param>
196
+ protected virtual void SubmitChoice(CallbackContext context)
197
+ {
198
+ if (inSelect)
199
+ {
200
+ string selectedText = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TMP_Text>().text;
201
+
202
+ MultipleChoiceOption selectedOption = builder.GetOptionWithText(selectedText);
203
+
204
+ if (selectedOption == null)
205
+ return;
206
+
207
+ ServiceLocator.GetService<SFXManagerBase>().PlaySubmit();
208
+
209
+ SetInSelect(false);
210
+
211
+ submit.action.started -= SubmitChoice;
212
+
213
+ EventSystem.current.SetSelectedGameObject(null);
214
+
215
+ if (TrialTimer != null)
216
+ TrialTimer.PauseTimer();
217
+
218
+ HideVisuals();
219
+
220
+ if (selectedOption.isAnswer)
221
+ StartCoroutine(ResolveMinigame());
222
+ else
223
+ TrialMistake(selectedOption.wrongDialogue);
224
+ }
225
+ }
226
+
227
+ /// <inheritdoc/>
228
+ public override IEnumerator ResolveMinigame()
229
+ {
230
+ yield return new WaitForSeconds(menuFadeWaitTime);
231
+
232
+ if (answerUI != null)
233
+ yield return answerUI.ShowTillComplete();
234
+
235
+ yield return base.ResolveMinigame();
236
+
237
+ yield break;
238
+ }
239
+
240
+ /// <summary>
241
+ ///
242
+ /// </summary>
243
+ protected virtual void HideVisuals()
244
+ {
245
+ if (TrialTimer != null)
246
+ TrialTimer.Hide();
247
+
248
+ gameUI.Hide();
249
+ }
250
+
251
+ /// <inheritdoc/>
252
+ protected override void Restart()
253
+ {
254
+ gameUI.Show();
255
+
256
+ EventSystem.current.SetSelectedGameObject(choices[0].gameObject);
257
+
258
+ if (TrialTimer != null)
259
+ TrialTimer.Show();
260
+
261
+ StartCoroutine(ResolveRestart());
262
+ }
263
+
264
+ /// <summary>
265
+ ///
266
+ /// </summary>
267
+ protected virtual IEnumerator ResolveRestart()
268
+ {
269
+ yield return TrialTimer.WaitForChangeToComplete();
270
+
271
+ if (TrialTimer != null)
272
+ TrialTimer.ResumeTimer();
273
+
274
+ yield return new WaitForSeconds(Time.deltaTime);
275
+
276
+ submit.action.started += SubmitChoice;
277
+
278
+ SetInSelect(true);
279
+
280
+ yield break;
281
+ }
282
+
283
+
284
+ /// <inheritdoc/>
285
+ protected override void OnTimeUp()
286
+ {
287
+ SetInSelect(false);
288
+
289
+ EventSystem.current.SetSelectedGameObject(null);
290
+
291
+ HideVisuals();
292
+
293
+ base.OnTimeUp();
294
+ }
295
+ }
296
296
  }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 3444e99d9ec4f034eacaa1b708ba758d
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 3444e99d9ec4f034eacaa1b708ba758d
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: