net.dreditor.dialogues.implementation 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.
- package/.attestation.p7m +0 -0
- package/DREditor.Dialogues.Implementation.asmdef +15 -15
- package/DREditor.Dialogues.Implementation.asmdef.meta +7 -7
- package/DialogueAssetDataClearer.cs +49 -49
- package/DialogueAssetDataClearer.cs.meta +11 -11
- package/DialogueAssetEndEventHandler.cs +57 -57
- package/DialogueAssetEndEventHandler.cs.meta +11 -11
- package/DialogueAssetEnder.cs +239 -239
- package/DialogueAssetEnder.cs.meta +11 -11
- package/DialogueAssetFinisher.cs +89 -89
- package/DialogueAssetFinisher.cs.meta +11 -11
- package/DialogueAssetFinisherBase.cs +82 -82
- package/DialogueAssetFinisherBase.cs.meta +11 -11
- package/DialogueAssetManager.cs +65 -65
- package/DialogueAssetManager.cs.meta +11 -11
- package/DialogueAssetReader.cs +377 -377
- package/DialogueAssetReader.cs.meta +11 -11
- package/DialogueAssetStarter.cs +254 -254
- package/DialogueAssetStarter.cs.meta +11 -11
- package/DialogueAssetStarterDebugger.cs +40 -40
- package/DialogueAssetStarterDebugger.cs.meta +11 -11
- package/DialogueAssetWaiter.cs +93 -93
- package/DialogueAssetWaiter.cs.meta +11 -11
- package/DialogueLineReader.cs +391 -391
- package/DialogueLineReader.cs.meta +11 -11
- package/DialogueManager.cs +83 -83
- package/DialogueManager.cs.meta +11 -11
- package/DialogueNameSaver.cs +45 -45
- package/DialogueNameSaver.cs.meta +11 -11
- package/FastForwardToLine.cs +102 -102
- package/FastForwardToLine.cs.meta +11 -11
- package/InstantDialogueEnder.cs +91 -91
- package/InstantDialogueEnder.cs.meta +11 -11
- package/InstantDialogueFinisher.cs +132 -132
- package/InstantDialogueFinisher.cs.meta +11 -11
- package/InstantDialogueStarter.cs +82 -82
- package/InstantDialogueStarter.cs.meta +11 -11
- package/NotLeavingOnDialogueFinish.cs +44 -44
- package/NotLeavingOnDialogueFinish.cs.meta +11 -11
- package/PreparableDialogueStarter.cs +88 -88
- package/PreparableDialogueStarter.cs.meta +11 -11
- package/{Samples → Samples~}/Dialogue_Asset_End_Event_Handler.prefab +685 -685
- package/{Samples → Samples~}/Dialogue_Asset_End_Event_Handler.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Ender.prefab +858 -858
- package/{Samples → Samples~}/Dialogue_Asset_Ender.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Finisher.prefab +301 -301
- package/{Samples → Samples~}/Dialogue_Asset_Finisher.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Load_Identifier.prefab +48 -48
- package/{Samples → Samples~}/Dialogue_Asset_Load_Identifier.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Loader.prefab +231 -231
- package/{Samples → Samples~}/Dialogue_Asset_Loader.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Reader_DRE.prefab +511 -511
- package/{Samples → Samples~}/Dialogue_Asset_Reader_DRE.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Reader_Shell.prefab +252 -252
- package/{Samples → Samples~}/Dialogue_Asset_Reader_Shell.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Reader_Template.prefab +193 -193
- package/{Samples → Samples~}/Dialogue_Asset_Reader_Template.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Starter.prefab +613 -613
- package/{Samples → Samples~}/Dialogue_Asset_Starter.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Asset_Waiter.prefab +50 -50
- package/{Samples → Samples~}/Dialogue_Asset_Waiter.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Events_Shell.prefab +458 -458
- package/{Samples → Samples~}/Dialogue_Events_Shell.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Events_Template.prefab +302 -302
- package/{Samples → Samples~}/Dialogue_Events_Template.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Line_Loader.prefab +1282 -1282
- package/{Samples → Samples~}/Dialogue_Line_Loader.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Line_Reader.prefab +3688 -3688
- package/{Samples → Samples~}/Dialogue_Line_Reader.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_Name_Saver.prefab +48 -48
- package/{Samples → Samples~}/Dialogue_Name_Saver.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_System_Shell.prefab +325 -325
- package/{Samples → Samples~}/Dialogue_System_Shell.prefab.meta +7 -7
- package/{Samples → Samples~}/Dialogue_System_Template.prefab +1138 -1138
- package/{Samples → Samples~}/Dialogue_System_Template.prefab.meta +7 -7
- package/{Samples → Samples~}/Fast_Forward_To_Line_Tool.prefab +53 -53
- package/{Samples → Samples~}/Fast_Forward_To_Line_Tool.prefab.meta +7 -7
- package/{Samples → Samples~}/Instant_Dialogue_Ender.prefab +141 -141
- package/{Samples → Samples~}/Instant_Dialogue_Ender.prefab.meta +7 -7
- package/{Samples → Samples~}/Instant_Dialogue_Finisher.prefab +172 -172
- package/{Samples → Samples~}/Instant_Dialogue_Finisher.prefab.meta +7 -7
- package/{Samples → Samples~}/Instant_Dialogue_Starter.prefab +55 -55
- package/{Samples → Samples~}/Instant_Dialogue_Starter.prefab.meta +7 -7
- package/{Samples → Samples~}/On_Loading_Through_Scene_Transition.prefab +48 -48
- package/{Samples → Samples~}/On_Loading_Through_Scene_Transition.prefab.meta +7 -7
- package/{Samples → Samples~}/Scene_Event_On_Text_Display.prefab +47 -47
- package/{Samples → Samples~}/Scene_Event_On_Text_Display.prefab.meta +7 -7
- package/{Samples → Samples~}/Trial_Dialogue_Asset_Reader.prefab +561 -561
- package/{Samples → Samples~}/Trial_Dialogue_Asset_Reader.prefab.meta +7 -7
- package/{Samples → Samples~}/Trial_Dialogue_Asset_Starter.prefab +239 -239
- package/{Samples → Samples~}/Trial_Dialogue_Asset_Starter.prefab.meta +7 -7
- package/{Samples → Samples~}/Trial_Dialogue_Line_Loader.prefab +941 -941
- package/{Samples → Samples~}/Trial_Dialogue_Line_Loader.prefab.meta +7 -7
- package/{Samples → Samples~}/Trial_Dialogue_Loader.prefab +232 -232
- package/{Samples → Samples~}/Trial_Dialogue_Loader.prefab.meta +7 -7
- package/{Samples → Samples~}/Tween_Waiter_Handler.prefab +46 -46
- package/{Samples → Samples~}/Tween_Waiter_Handler.prefab.meta +7 -7
- package/package.json +39 -34
- package/package.json.meta +7 -7
- package/Samples.meta +0 -8
package/DialogueAssetReader.cs
CHANGED
|
@@ -1,378 +1,378 @@
|
|
|
1
|
-
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
-
using DREditor.Dialogues.Ending;
|
|
3
|
-
using DREditor.Dialogues.LineReading;
|
|
4
|
-
using DREditor.Dialogues.Loading;
|
|
5
|
-
using DREditor.EventObjects;
|
|
6
|
-
using DREditor.Services;
|
|
7
|
-
using System;
|
|
8
|
-
using System.Collections;
|
|
9
|
-
using System.Collections.Generic;
|
|
10
|
-
using System.Linq;
|
|
11
|
-
using UnityEngine;
|
|
12
|
-
|
|
13
|
-
namespace DREditor.Dialogues.Implementation
|
|
14
|
-
{
|
|
15
|
-
/// <summary>
|
|
16
|
-
///
|
|
17
|
-
/// </summary>
|
|
18
|
-
/// <remarks></remarks>
|
|
19
|
-
public class DialogueAssetReader : DialogueReader, IToTitleScreen
|
|
20
|
-
{
|
|
21
|
-
#region Fields
|
|
22
|
-
|
|
23
|
-
/// <summary>
|
|
24
|
-
///
|
|
25
|
-
/// </summary>
|
|
26
|
-
[Header("")]
|
|
27
|
-
[Divider]
|
|
28
|
-
[Tooltip("")]
|
|
29
|
-
[SerializeField] DialogueCore currentlyPlayingDialogue;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/// <summary>
|
|
33
|
-
///
|
|
34
|
-
/// </summary>
|
|
35
|
-
[Header("")]
|
|
36
|
-
[Divider]
|
|
37
|
-
[Tooltip("")]
|
|
38
|
-
[SerializeField] protected DialogueEndEventHandler DialogueEndEventHandler = null;
|
|
39
|
-
|
|
40
|
-
/// <summary>
|
|
41
|
-
///
|
|
42
|
-
/// </summary>
|
|
43
|
-
[Tooltip("")]
|
|
44
|
-
[SerializeField] protected DialogueEnder DialogueEnder = null;
|
|
45
|
-
|
|
46
|
-
/// <summary>
|
|
47
|
-
///
|
|
48
|
-
/// </summary>
|
|
49
|
-
[Tooltip("")]
|
|
50
|
-
[SerializeField] protected DialogueDataClearer DialogueClearer = null;
|
|
51
|
-
|
|
52
|
-
/// <summary>
|
|
53
|
-
///
|
|
54
|
-
/// </summary>
|
|
55
|
-
[Tooltip("")]
|
|
56
|
-
[SerializeField] protected DialogueLoader DialogueLoader = null;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
/// <summary>
|
|
60
|
-
///
|
|
61
|
-
/// </summary>
|
|
62
|
-
[Header("")]
|
|
63
|
-
[Divider]
|
|
64
|
-
[Tooltip("")]
|
|
65
|
-
[SerializeField] protected IntWithEvent currentLineNum = null;
|
|
66
|
-
|
|
67
|
-
/// <summary>
|
|
68
|
-
///
|
|
69
|
-
/// </summary>
|
|
70
|
-
[Tooltip("")]
|
|
71
|
-
[SerializeField] protected SceneEvent updateDirectTo = null;
|
|
72
|
-
|
|
73
|
-
/// <summary>
|
|
74
|
-
///
|
|
75
|
-
/// </summary>
|
|
76
|
-
[Tooltip("")]
|
|
77
|
-
[SerializeField] protected BoolWithEvent isLeaving = null;
|
|
78
|
-
|
|
79
|
-
/// <summary>
|
|
80
|
-
///
|
|
81
|
-
/// </summary>
|
|
82
|
-
[Tooltip("")]
|
|
83
|
-
[SerializeField] protected BoolWithEvent isLoadingFile = null;
|
|
84
|
-
|
|
85
|
-
/// <summary>
|
|
86
|
-
///
|
|
87
|
-
/// </summary>
|
|
88
|
-
[Tooltip("")]
|
|
89
|
-
[SerializeField] protected StringWithEvent saveDialogueName = null;
|
|
90
|
-
|
|
91
|
-
/// <summary>
|
|
92
|
-
///
|
|
93
|
-
/// </summary>
|
|
94
|
-
[Tooltip("")]
|
|
95
|
-
[SerializeField] protected LineReader LineReader = null;
|
|
96
|
-
|
|
97
|
-
/// <summary>
|
|
98
|
-
///
|
|
99
|
-
/// </summary>
|
|
100
|
-
[Tooltip("")]
|
|
101
|
-
[SerializeField] protected List<DialogueComponent> DialogueReaderInitializeComponents = new();
|
|
102
|
-
|
|
103
|
-
/// <summary>
|
|
104
|
-
///
|
|
105
|
-
/// </summary>
|
|
106
|
-
[Tooltip("")]
|
|
107
|
-
[SerializeField] protected List<DialogueComponent> DialogueReaderCleanUpComponents = new();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/// <summary>
|
|
111
|
-
///
|
|
112
|
-
/// </summary>
|
|
113
|
-
protected IEnumerable<IDialogueInteruptable> interuptables;
|
|
114
|
-
|
|
115
|
-
/// <summary>
|
|
116
|
-
///
|
|
117
|
-
/// </summary>
|
|
118
|
-
protected int lastLineNum = -1;
|
|
119
|
-
|
|
120
|
-
#endregion
|
|
121
|
-
|
|
122
|
-
#region Awake/Enable/Disable/Reset
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
protected virtual void Awake() => interuptables = transform.root.GetComponentsInChildren<IDialogueInteruptable>();
|
|
126
|
-
|
|
127
|
-
/// <summary>
|
|
128
|
-
///
|
|
129
|
-
/// </summary>
|
|
130
|
-
protected virtual void OnEnable() => SubscribeToEvents();
|
|
131
|
-
|
|
132
|
-
/// <summary>
|
|
133
|
-
///
|
|
134
|
-
/// </summary>
|
|
135
|
-
protected virtual void SubscribeToEvents()
|
|
136
|
-
{
|
|
137
|
-
foreach (var interuptable in interuptables)
|
|
138
|
-
interuptable.OnInteruptWithNewDialogue += PlayDialogues;
|
|
139
|
-
|
|
140
|
-
DialogueEndEventHandler.SubscribeToCleanUp(CleanUp);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/// <summary>
|
|
145
|
-
///
|
|
146
|
-
/// </summary>
|
|
147
|
-
protected virtual void OnDisable() => UnsubscribeToEvents();
|
|
148
|
-
|
|
149
|
-
/// <summary>
|
|
150
|
-
///
|
|
151
|
-
/// </summary>
|
|
152
|
-
protected virtual void UnsubscribeToEvents()
|
|
153
|
-
{
|
|
154
|
-
foreach (var interuptable in interuptables)
|
|
155
|
-
interuptable.OnInteruptWithNewDialogue -= PlayDialogues;
|
|
156
|
-
|
|
157
|
-
DialogueEndEventHandler.UnsubscribeToCleanUp(CleanUp);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
#endregion
|
|
161
|
-
|
|
162
|
-
#region Play Dialogues
|
|
163
|
-
|
|
164
|
-
/// <summary>
|
|
165
|
-
///
|
|
166
|
-
/// </summary>
|
|
167
|
-
/// <param name="dialogues"></param>
|
|
168
|
-
/// <remarks></remarks>
|
|
169
|
-
public virtual void PlayDialogues(DialogueCore[] dialogues)
|
|
170
|
-
{
|
|
171
|
-
List<Dialogue> dias = new();
|
|
172
|
-
|
|
173
|
-
foreach(DialogueCore dialogue in dialogues)
|
|
174
|
-
if (dialogue is Dialogue dia)
|
|
175
|
-
dias.Add(dia);
|
|
176
|
-
else
|
|
177
|
-
UnityEngine.Debug.LogWarning("ALERT: ISSUE PLAYING DIALOGUE WAS NOT OF DIALOGUE TYPE");
|
|
178
|
-
|
|
179
|
-
StartCoroutine(PlayDialoguesRoutine(dias.ToArray()));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/// <summary>
|
|
183
|
-
///
|
|
184
|
-
/// </summary>
|
|
185
|
-
/// <param name="dialogues"></param>
|
|
186
|
-
/// <param name="inLeave"></param>
|
|
187
|
-
public override void PlayDialogues<T>(DialogueBase<T>[] dialogues, bool inLeave = false) =>
|
|
188
|
-
StartCoroutine(PlayDialoguesRoutine<T>(dialogues, inLeave));
|
|
189
|
-
|
|
190
|
-
/// <summary>
|
|
191
|
-
///
|
|
192
|
-
/// </summary>
|
|
193
|
-
/// <param name="dialogues"></param>
|
|
194
|
-
/// <param name="intendingToLeave"></param>
|
|
195
|
-
/// <returns></returns>
|
|
196
|
-
protected virtual IEnumerator PlayDialoguesRoutine<T>(DialogueBase<T>[] dialogues, bool intendingToLeave = false)
|
|
197
|
-
where T : Line
|
|
198
|
-
{
|
|
199
|
-
isLeaving.SetValue(intendingToLeave);
|
|
200
|
-
|
|
201
|
-
InitializeDialogueStarting();
|
|
202
|
-
|
|
203
|
-
for (int i = 0; i < dialogues.Length; i++)
|
|
204
|
-
{
|
|
205
|
-
DialogueBase<T> currentDialogue = dialogues[i];
|
|
206
|
-
|
|
207
|
-
if (i != 0)
|
|
208
|
-
updateDirectTo.Raise();
|
|
209
|
-
|
|
210
|
-
bool stopParent = false;
|
|
211
|
-
|
|
212
|
-
yield return PlayDialogue(currentDialogue, () => stopParent = true);
|
|
213
|
-
|
|
214
|
-
LineReader.ClearSaveData();
|
|
215
|
-
|
|
216
|
-
if (stopParent)
|
|
217
|
-
yield break;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
CleanUp();
|
|
221
|
-
|
|
222
|
-
DialogueEnder.StopDialogue();
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/// <summary>
|
|
226
|
-
///
|
|
227
|
-
/// </summary>
|
|
228
|
-
protected virtual void InitializeDialogueStarting()
|
|
229
|
-
{
|
|
230
|
-
if (!isLoadingFile.Value)
|
|
231
|
-
LineReader.ClearSaveDataOnDialogueStart();
|
|
232
|
-
|
|
233
|
-
foreach (IDialogueReaderInitialize initializer in DialogueReaderInitializeComponents.Cast<IDialogueReaderInitialize>())
|
|
234
|
-
initializer.OnDialogueReaderInitialize();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/// <summary>
|
|
238
|
-
///
|
|
239
|
-
/// </summary>
|
|
240
|
-
public override void CleanUp()
|
|
241
|
-
{
|
|
242
|
-
DialogueClearer.ClearSaveData();
|
|
243
|
-
|
|
244
|
-
foreach (IDialogueReaderCleanUp cleanUpComponent in DialogueReaderCleanUpComponents.Cast<IDialogueReaderCleanUp>())
|
|
245
|
-
cleanUpComponent?.OnDialogueReaderCleanUp();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
#endregion
|
|
249
|
-
|
|
250
|
-
#region Play Dialogue
|
|
251
|
-
|
|
252
|
-
/// <summary>
|
|
253
|
-
///
|
|
254
|
-
/// </summary>
|
|
255
|
-
/// <typeparam name="T"></typeparam>
|
|
256
|
-
/// <param name="currentDialogue"></param>
|
|
257
|
-
/// <param name="exitParentRoutine"></param>
|
|
258
|
-
protected virtual IEnumerator PlayDialogue<T>(DialogueBase<T> currentDialogue, Action exitParentRoutine = null)
|
|
259
|
-
where T : Line
|
|
260
|
-
{
|
|
261
|
-
currentlyPlayingDialogue = currentDialogue;
|
|
262
|
-
|
|
263
|
-
for (int i = 0; i < currentDialogue.Lines.Count; i++)
|
|
264
|
-
{
|
|
265
|
-
Line currentLine = currentDialogue.Lines[i];
|
|
266
|
-
|
|
267
|
-
if (isLoadingFile.Value)
|
|
268
|
-
yield return DialogueLoader.LoadToDialogueLine<T>(currentDialogue,
|
|
269
|
-
loadedIndex => { i = loadedIndex; currentLine = currentDialogue.Lines[i]; });
|
|
270
|
-
|
|
271
|
-
SetLineNumber(i);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
bool exitEarly = false;
|
|
275
|
-
|
|
276
|
-
bool continueLine = false;
|
|
277
|
-
|
|
278
|
-
yield return LineReader.PlayDialogueLine(currentDialogue, currentLine, () => exitEarly = true, () => continueLine = true);
|
|
279
|
-
|
|
280
|
-
if (exitEarly)
|
|
281
|
-
{
|
|
282
|
-
exitParentRoutine?.Invoke();
|
|
283
|
-
|
|
284
|
-
yield break;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (continueLine)
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// The dialogue reader has finished reading the dialogue lines.
|
|
292
|
-
|
|
293
|
-
SetLineOutOfBounds();
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
bool exitParent = false;
|
|
297
|
-
|
|
298
|
-
yield return DialogueEndEventHandler.EndDialogueEventOptions(currentDialogue, () => exitParent = true);
|
|
299
|
-
|
|
300
|
-
if (exitParent)
|
|
301
|
-
exitParentRoutine?.Invoke();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/// <summary>
|
|
305
|
-
///
|
|
306
|
-
/// </summary>
|
|
307
|
-
/// <param name="currentLineNum"></param>
|
|
308
|
-
protected virtual void SetLineNumber(int currentLineNum) => this.currentLineNum.SetValue(currentLineNum);
|
|
309
|
-
|
|
310
|
-
/// <summary>
|
|
311
|
-
///
|
|
312
|
-
/// </summary>
|
|
313
|
-
protected virtual void SetLineOutOfBounds()
|
|
314
|
-
{
|
|
315
|
-
lastLineNum = currentLineNum.Value;
|
|
316
|
-
|
|
317
|
-
SetLineNumber(-1);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
#endregion
|
|
321
|
-
|
|
322
|
-
#region Additional Public Functions
|
|
323
|
-
|
|
324
|
-
/// <inheritdoc/>
|
|
325
|
-
public override void MidDialogueEnterance<T>(DialogueBase<T>[] dialogues)
|
|
326
|
-
{
|
|
327
|
-
if (dialogues.Length == 0)
|
|
328
|
-
{
|
|
329
|
-
UnityEngine.Debug.LogWarning("ALERT: Tried to send MidDialogue without dialogues!");
|
|
330
|
-
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
DialogueClearer.ClearSaveData();
|
|
335
|
-
|
|
336
|
-
saveDialogueName.SetValue(dialogues[0].name);
|
|
337
|
-
|
|
338
|
-
PlayDialogues<T>(dialogues);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/// <inheritdoc/>
|
|
342
|
-
public override bool IsOnLastLine() =>
|
|
343
|
-
GetCurrentDialogue() != null && GetCurrentLineNum() == GetCurrentDialogue().LineCount - 1;
|
|
344
|
-
|
|
345
|
-
/// <inheritdoc/>
|
|
346
|
-
public override DialogueCore GetCurrentDialogue() => currentlyPlayingDialogue;
|
|
347
|
-
|
|
348
|
-
/// <inheritdoc/>
|
|
349
|
-
public override int GetCurrentLineNum() => currentLineNum.Value;
|
|
350
|
-
|
|
351
|
-
/// <inheritdoc/>
|
|
352
|
-
public override Line GetCurrentLine()
|
|
353
|
-
{
|
|
354
|
-
int currentLineNumber = GetCurrentLineNum();
|
|
355
|
-
|
|
356
|
-
bool linesAreBeingRead = currentLineNumber != -1;
|
|
357
|
-
|
|
358
|
-
int lineNumber = linesAreBeingRead ? currentLineNumber : lastLineNum;
|
|
359
|
-
|
|
360
|
-
if (linesAreBeingRead)
|
|
361
|
-
lastLineNum = -1;
|
|
362
|
-
|
|
363
|
-
return GetCurrentDialogue().GetLine(lineNumber);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/// <summary>
|
|
367
|
-
///
|
|
368
|
-
/// </summary>
|
|
369
|
-
public virtual void ToTitleScreen()
|
|
370
|
-
{
|
|
371
|
-
SetLineOutOfBounds();
|
|
372
|
-
|
|
373
|
-
StopAllCoroutines();
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
#endregion
|
|
377
|
-
}
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.Dialogues.Ending;
|
|
3
|
+
using DREditor.Dialogues.LineReading;
|
|
4
|
+
using DREditor.Dialogues.Loading;
|
|
5
|
+
using DREditor.EventObjects;
|
|
6
|
+
using DREditor.Services;
|
|
7
|
+
using System;
|
|
8
|
+
using System.Collections;
|
|
9
|
+
using System.Collections.Generic;
|
|
10
|
+
using System.Linq;
|
|
11
|
+
using UnityEngine;
|
|
12
|
+
|
|
13
|
+
namespace DREditor.Dialogues.Implementation
|
|
14
|
+
{
|
|
15
|
+
/// <summary>
|
|
16
|
+
///
|
|
17
|
+
/// </summary>
|
|
18
|
+
/// <remarks></remarks>
|
|
19
|
+
public class DialogueAssetReader : DialogueReader, IToTitleScreen
|
|
20
|
+
{
|
|
21
|
+
#region Fields
|
|
22
|
+
|
|
23
|
+
/// <summary>
|
|
24
|
+
///
|
|
25
|
+
/// </summary>
|
|
26
|
+
[Header("")]
|
|
27
|
+
[Divider]
|
|
28
|
+
[Tooltip("")]
|
|
29
|
+
[SerializeField] DialogueCore currentlyPlayingDialogue;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/// <summary>
|
|
33
|
+
///
|
|
34
|
+
/// </summary>
|
|
35
|
+
[Header("")]
|
|
36
|
+
[Divider]
|
|
37
|
+
[Tooltip("")]
|
|
38
|
+
[SerializeField] protected DialogueEndEventHandler DialogueEndEventHandler = null;
|
|
39
|
+
|
|
40
|
+
/// <summary>
|
|
41
|
+
///
|
|
42
|
+
/// </summary>
|
|
43
|
+
[Tooltip("")]
|
|
44
|
+
[SerializeField] protected DialogueEnder DialogueEnder = null;
|
|
45
|
+
|
|
46
|
+
/// <summary>
|
|
47
|
+
///
|
|
48
|
+
/// </summary>
|
|
49
|
+
[Tooltip("")]
|
|
50
|
+
[SerializeField] protected DialogueDataClearer DialogueClearer = null;
|
|
51
|
+
|
|
52
|
+
/// <summary>
|
|
53
|
+
///
|
|
54
|
+
/// </summary>
|
|
55
|
+
[Tooltip("")]
|
|
56
|
+
[SerializeField] protected DialogueLoader DialogueLoader = null;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
///
|
|
61
|
+
/// </summary>
|
|
62
|
+
[Header("")]
|
|
63
|
+
[Divider]
|
|
64
|
+
[Tooltip("")]
|
|
65
|
+
[SerializeField] protected IntWithEvent currentLineNum = null;
|
|
66
|
+
|
|
67
|
+
/// <summary>
|
|
68
|
+
///
|
|
69
|
+
/// </summary>
|
|
70
|
+
[Tooltip("")]
|
|
71
|
+
[SerializeField] protected SceneEvent updateDirectTo = null;
|
|
72
|
+
|
|
73
|
+
/// <summary>
|
|
74
|
+
///
|
|
75
|
+
/// </summary>
|
|
76
|
+
[Tooltip("")]
|
|
77
|
+
[SerializeField] protected BoolWithEvent isLeaving = null;
|
|
78
|
+
|
|
79
|
+
/// <summary>
|
|
80
|
+
///
|
|
81
|
+
/// </summary>
|
|
82
|
+
[Tooltip("")]
|
|
83
|
+
[SerializeField] protected BoolWithEvent isLoadingFile = null;
|
|
84
|
+
|
|
85
|
+
/// <summary>
|
|
86
|
+
///
|
|
87
|
+
/// </summary>
|
|
88
|
+
[Tooltip("")]
|
|
89
|
+
[SerializeField] protected StringWithEvent saveDialogueName = null;
|
|
90
|
+
|
|
91
|
+
/// <summary>
|
|
92
|
+
///
|
|
93
|
+
/// </summary>
|
|
94
|
+
[Tooltip("")]
|
|
95
|
+
[SerializeField] protected LineReader LineReader = null;
|
|
96
|
+
|
|
97
|
+
/// <summary>
|
|
98
|
+
///
|
|
99
|
+
/// </summary>
|
|
100
|
+
[Tooltip("")]
|
|
101
|
+
[SerializeField] protected List<DialogueComponent> DialogueReaderInitializeComponents = new();
|
|
102
|
+
|
|
103
|
+
/// <summary>
|
|
104
|
+
///
|
|
105
|
+
/// </summary>
|
|
106
|
+
[Tooltip("")]
|
|
107
|
+
[SerializeField] protected List<DialogueComponent> DialogueReaderCleanUpComponents = new();
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
/// <summary>
|
|
111
|
+
///
|
|
112
|
+
/// </summary>
|
|
113
|
+
protected IEnumerable<IDialogueInteruptable> interuptables;
|
|
114
|
+
|
|
115
|
+
/// <summary>
|
|
116
|
+
///
|
|
117
|
+
/// </summary>
|
|
118
|
+
protected int lastLineNum = -1;
|
|
119
|
+
|
|
120
|
+
#endregion
|
|
121
|
+
|
|
122
|
+
#region Awake/Enable/Disable/Reset
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
protected virtual void Awake() => interuptables = transform.root.GetComponentsInChildren<IDialogueInteruptable>();
|
|
126
|
+
|
|
127
|
+
/// <summary>
|
|
128
|
+
///
|
|
129
|
+
/// </summary>
|
|
130
|
+
protected virtual void OnEnable() => SubscribeToEvents();
|
|
131
|
+
|
|
132
|
+
/// <summary>
|
|
133
|
+
///
|
|
134
|
+
/// </summary>
|
|
135
|
+
protected virtual void SubscribeToEvents()
|
|
136
|
+
{
|
|
137
|
+
foreach (var interuptable in interuptables)
|
|
138
|
+
interuptable.OnInteruptWithNewDialogue += PlayDialogues;
|
|
139
|
+
|
|
140
|
+
DialogueEndEventHandler.SubscribeToCleanUp(CleanUp);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
/// <summary>
|
|
145
|
+
///
|
|
146
|
+
/// </summary>
|
|
147
|
+
protected virtual void OnDisable() => UnsubscribeToEvents();
|
|
148
|
+
|
|
149
|
+
/// <summary>
|
|
150
|
+
///
|
|
151
|
+
/// </summary>
|
|
152
|
+
protected virtual void UnsubscribeToEvents()
|
|
153
|
+
{
|
|
154
|
+
foreach (var interuptable in interuptables)
|
|
155
|
+
interuptable.OnInteruptWithNewDialogue -= PlayDialogues;
|
|
156
|
+
|
|
157
|
+
DialogueEndEventHandler.UnsubscribeToCleanUp(CleanUp);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#endregion
|
|
161
|
+
|
|
162
|
+
#region Play Dialogues
|
|
163
|
+
|
|
164
|
+
/// <summary>
|
|
165
|
+
///
|
|
166
|
+
/// </summary>
|
|
167
|
+
/// <param name="dialogues"></param>
|
|
168
|
+
/// <remarks></remarks>
|
|
169
|
+
public virtual void PlayDialogues(DialogueCore[] dialogues)
|
|
170
|
+
{
|
|
171
|
+
List<Dialogue> dias = new();
|
|
172
|
+
|
|
173
|
+
foreach(DialogueCore dialogue in dialogues)
|
|
174
|
+
if (dialogue is Dialogue dia)
|
|
175
|
+
dias.Add(dia);
|
|
176
|
+
else
|
|
177
|
+
UnityEngine.Debug.LogWarning("ALERT: ISSUE PLAYING DIALOGUE WAS NOT OF DIALOGUE TYPE");
|
|
178
|
+
|
|
179
|
+
StartCoroutine(PlayDialoguesRoutine(dias.ToArray()));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// <summary>
|
|
183
|
+
///
|
|
184
|
+
/// </summary>
|
|
185
|
+
/// <param name="dialogues"></param>
|
|
186
|
+
/// <param name="inLeave"></param>
|
|
187
|
+
public override void PlayDialogues<T>(DialogueBase<T>[] dialogues, bool inLeave = false) =>
|
|
188
|
+
StartCoroutine(PlayDialoguesRoutine<T>(dialogues, inLeave));
|
|
189
|
+
|
|
190
|
+
/// <summary>
|
|
191
|
+
///
|
|
192
|
+
/// </summary>
|
|
193
|
+
/// <param name="dialogues"></param>
|
|
194
|
+
/// <param name="intendingToLeave"></param>
|
|
195
|
+
/// <returns></returns>
|
|
196
|
+
protected virtual IEnumerator PlayDialoguesRoutine<T>(DialogueBase<T>[] dialogues, bool intendingToLeave = false)
|
|
197
|
+
where T : Line
|
|
198
|
+
{
|
|
199
|
+
isLeaving.SetValue(intendingToLeave);
|
|
200
|
+
|
|
201
|
+
InitializeDialogueStarting();
|
|
202
|
+
|
|
203
|
+
for (int i = 0; i < dialogues.Length; i++)
|
|
204
|
+
{
|
|
205
|
+
DialogueBase<T> currentDialogue = dialogues[i];
|
|
206
|
+
|
|
207
|
+
if (i != 0)
|
|
208
|
+
updateDirectTo.Raise();
|
|
209
|
+
|
|
210
|
+
bool stopParent = false;
|
|
211
|
+
|
|
212
|
+
yield return PlayDialogue(currentDialogue, () => stopParent = true);
|
|
213
|
+
|
|
214
|
+
LineReader.ClearSaveData();
|
|
215
|
+
|
|
216
|
+
if (stopParent)
|
|
217
|
+
yield break;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
CleanUp();
|
|
221
|
+
|
|
222
|
+
DialogueEnder.StopDialogue();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/// <summary>
|
|
226
|
+
///
|
|
227
|
+
/// </summary>
|
|
228
|
+
protected virtual void InitializeDialogueStarting()
|
|
229
|
+
{
|
|
230
|
+
if (!isLoadingFile.Value)
|
|
231
|
+
LineReader.ClearSaveDataOnDialogueStart();
|
|
232
|
+
|
|
233
|
+
foreach (IDialogueReaderInitialize initializer in DialogueReaderInitializeComponents.Cast<IDialogueReaderInitialize>())
|
|
234
|
+
initializer.OnDialogueReaderInitialize();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/// <summary>
|
|
238
|
+
///
|
|
239
|
+
/// </summary>
|
|
240
|
+
public override void CleanUp()
|
|
241
|
+
{
|
|
242
|
+
DialogueClearer.ClearSaveData();
|
|
243
|
+
|
|
244
|
+
foreach (IDialogueReaderCleanUp cleanUpComponent in DialogueReaderCleanUpComponents.Cast<IDialogueReaderCleanUp>())
|
|
245
|
+
cleanUpComponent?.OnDialogueReaderCleanUp();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
#endregion
|
|
249
|
+
|
|
250
|
+
#region Play Dialogue
|
|
251
|
+
|
|
252
|
+
/// <summary>
|
|
253
|
+
///
|
|
254
|
+
/// </summary>
|
|
255
|
+
/// <typeparam name="T"></typeparam>
|
|
256
|
+
/// <param name="currentDialogue"></param>
|
|
257
|
+
/// <param name="exitParentRoutine"></param>
|
|
258
|
+
protected virtual IEnumerator PlayDialogue<T>(DialogueBase<T> currentDialogue, Action exitParentRoutine = null)
|
|
259
|
+
where T : Line
|
|
260
|
+
{
|
|
261
|
+
currentlyPlayingDialogue = currentDialogue;
|
|
262
|
+
|
|
263
|
+
for (int i = 0; i < currentDialogue.Lines.Count; i++)
|
|
264
|
+
{
|
|
265
|
+
Line currentLine = currentDialogue.Lines[i];
|
|
266
|
+
|
|
267
|
+
if (isLoadingFile.Value)
|
|
268
|
+
yield return DialogueLoader.LoadToDialogueLine<T>(currentDialogue,
|
|
269
|
+
loadedIndex => { i = loadedIndex; currentLine = currentDialogue.Lines[i]; });
|
|
270
|
+
|
|
271
|
+
SetLineNumber(i);
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
bool exitEarly = false;
|
|
275
|
+
|
|
276
|
+
bool continueLine = false;
|
|
277
|
+
|
|
278
|
+
yield return LineReader.PlayDialogueLine(currentDialogue, currentLine, () => exitEarly = true, () => continueLine = true);
|
|
279
|
+
|
|
280
|
+
if (exitEarly)
|
|
281
|
+
{
|
|
282
|
+
exitParentRoutine?.Invoke();
|
|
283
|
+
|
|
284
|
+
yield break;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (continueLine)
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// The dialogue reader has finished reading the dialogue lines.
|
|
292
|
+
|
|
293
|
+
SetLineOutOfBounds();
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
bool exitParent = false;
|
|
297
|
+
|
|
298
|
+
yield return DialogueEndEventHandler.EndDialogueEventOptions(currentDialogue, () => exitParent = true);
|
|
299
|
+
|
|
300
|
+
if (exitParent)
|
|
301
|
+
exitParentRoutine?.Invoke();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/// <summary>
|
|
305
|
+
///
|
|
306
|
+
/// </summary>
|
|
307
|
+
/// <param name="currentLineNum"></param>
|
|
308
|
+
protected virtual void SetLineNumber(int currentLineNum) => this.currentLineNum.SetValue(currentLineNum);
|
|
309
|
+
|
|
310
|
+
/// <summary>
|
|
311
|
+
///
|
|
312
|
+
/// </summary>
|
|
313
|
+
protected virtual void SetLineOutOfBounds()
|
|
314
|
+
{
|
|
315
|
+
lastLineNum = currentLineNum.Value;
|
|
316
|
+
|
|
317
|
+
SetLineNumber(-1);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
#endregion
|
|
321
|
+
|
|
322
|
+
#region Additional Public Functions
|
|
323
|
+
|
|
324
|
+
/// <inheritdoc/>
|
|
325
|
+
public override void MidDialogueEnterance<T>(DialogueBase<T>[] dialogues)
|
|
326
|
+
{
|
|
327
|
+
if (dialogues.Length == 0)
|
|
328
|
+
{
|
|
329
|
+
UnityEngine.Debug.LogWarning("ALERT: Tried to send MidDialogue without dialogues!");
|
|
330
|
+
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
DialogueClearer.ClearSaveData();
|
|
335
|
+
|
|
336
|
+
saveDialogueName.SetValue(dialogues[0].name);
|
|
337
|
+
|
|
338
|
+
PlayDialogues<T>(dialogues);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/// <inheritdoc/>
|
|
342
|
+
public override bool IsOnLastLine() =>
|
|
343
|
+
GetCurrentDialogue() != null && GetCurrentLineNum() == GetCurrentDialogue().LineCount - 1;
|
|
344
|
+
|
|
345
|
+
/// <inheritdoc/>
|
|
346
|
+
public override DialogueCore GetCurrentDialogue() => currentlyPlayingDialogue;
|
|
347
|
+
|
|
348
|
+
/// <inheritdoc/>
|
|
349
|
+
public override int GetCurrentLineNum() => currentLineNum.Value;
|
|
350
|
+
|
|
351
|
+
/// <inheritdoc/>
|
|
352
|
+
public override Line GetCurrentLine()
|
|
353
|
+
{
|
|
354
|
+
int currentLineNumber = GetCurrentLineNum();
|
|
355
|
+
|
|
356
|
+
bool linesAreBeingRead = currentLineNumber != -1;
|
|
357
|
+
|
|
358
|
+
int lineNumber = linesAreBeingRead ? currentLineNumber : lastLineNum;
|
|
359
|
+
|
|
360
|
+
if (linesAreBeingRead)
|
|
361
|
+
lastLineNum = -1;
|
|
362
|
+
|
|
363
|
+
return GetCurrentDialogue().GetLine(lineNumber);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/// <summary>
|
|
367
|
+
///
|
|
368
|
+
/// </summary>
|
|
369
|
+
public virtual void ToTitleScreen()
|
|
370
|
+
{
|
|
371
|
+
SetLineOutOfBounds();
|
|
372
|
+
|
|
373
|
+
StopAllCoroutines();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
#endregion
|
|
377
|
+
}
|
|
378
378
|
}
|