Skip to content

Commit 14727b4

Browse files
committed
Added wait command
1 parent 08e985a commit 14727b4

5 files changed

Lines changed: 72 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Added Offset property for all animated properties.
99
- Added Active toggle to text effect.
1010
- Added pause functionality.
11+
- Added Wait Command (%[time]/%).
1112

1213
### Changed
1314
- Changed DialogueTheme and DialogueSettings to ScriptableObjects.

Scripts/Runtime/DialogueHandler.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,12 @@ string ProcessText(string line)
619619
str.Clear();
620620
ui.Reset();
621621

622-
Regex reg = new Regex(@"<.*?/>");
623-
MatchCollection regexMatches = reg.Matches(line);
624-
string interpolatedText = ReplaceWords(regexMatches, line);
622+
Regex dictionaryRegex = new Regex(@"<.*?\/>");
623+
Regex waitRegex = new Regex(@"%.*?\/%");
624+
625+
626+
MatchCollection dictionaryRegexMatches = dictionaryRegex.Matches(line);
627+
string interpolatedText = ReplaceWords(dictionaryRegexMatches, line);
625628

626629
List<int> CmdObjectIndex = interpolatedText.AllIndexesOf("{");
627630

@@ -645,6 +648,8 @@ string ProcessText(string line)
645648
}
646649
}
647650

651+
SetWaitIndicesRecursive();
652+
648653
return str.ToString();
649654
}
650655

@@ -676,6 +681,34 @@ string ReplaceWords(MatchCollection matches, string originalString)
676681
return interpolatedString;
677682
}
678683

684+
void SetWaitIndicesRecursive()
685+
{
686+
Regex waitRegex = new Regex(@"%.*?\/%");
687+
Match match = waitRegex.Match(str.ToString());
688+
689+
if(match.Success)
690+
{
691+
Group key = match.Groups[0];
692+
693+
Debug.Log(key.Value);
694+
string waitString = key.Value.Substring(1, key.Value.Length - 3);
695+
Debug.Log(waitString);
696+
if (float.TryParse(waitString, out float waitTime))
697+
{
698+
699+
str.Replace(key.Value, "", match.Index, key.Value.Length);
700+
ui.RegisterWaitIndex(match.Index - 1, waitTime);
701+
702+
SetWaitIndicesRecursive();
703+
}
704+
else
705+
{
706+
Debug.LogError($"Invalid wait command found: {waitString}");
707+
}
708+
}
709+
710+
}
711+
679712
}
680713

681714
[Serializable]

Scripts/Runtime/DialogueUI.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ public void RegisterTextEffectIndices(TextCommand command, int startIndex, int e
125125
}
126126

127127
}
128+
}
128129

130+
public void RegisterWaitIndex(int index, float waitTime)
131+
{
132+
textEffects.SetWaitIndex(index, waitTime);
129133
}
130134

131135
public void Pause(bool toggle)

Scripts/Runtime/TextEffects.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public CharacterInfo(float duration)
4242
private Dictionary<int, Color> colorIndices = new Dictionary<int, Color>();
4343
private Dictionary<int, CharacterInfo> characterMap = new Dictionary<int, CharacterInfo>();
4444
private List<TextEffectWrapper> _textEffects = new List<TextEffectWrapper>();
45+
private Dictionary<int, float> _waitIndices = new Dictionary<int, float>();
4546

4647
public enum TextDisplayMode
4748
{
@@ -93,11 +94,17 @@ public void SetEffectIndices(TextEffect fx, int start, int end)
9394
_textEffects.Add(wrapper);
9495
}
9596

97+
public void SetWaitIndex(int index, float time)
98+
{
99+
_waitIndices.Add(index, time);
100+
}
101+
96102
public void ClearAllIndices()
97103
{
98104
colorIndices.Clear();
99105
characterMap.Clear();
100106
_textEffects.Clear();
107+
_waitIndices.Clear();
101108
}
102109

103110
public void Init(DialogueTheme theme, DialogueSettings settings, DialogueCallbackActions callbackActions = null)
@@ -145,12 +152,17 @@ public IEnumerator TypewriterEffect(Action<DialogueEventType> callback, float? s
145152
if (speedOverride != null)
146153
{
147154
typeWriterWaitTime = speedOverride.Value;
148-
149155
}
150156
else
151157
{
152158
typeWriterWaitTime = speedUp ? DialogueUtilities.DecreasingFunction(settings.typewriterSpeed * settings.typewriterSpeedMultiplier) : DialogueUtilities.DecreasingFunction(settings.typewriterSpeed);
153159
}
160+
161+
if (_waitIndices.TryGetValue(i, out float waitTime))
162+
{
163+
typeWriterWaitTime = waitTime;
164+
}
165+
154166
yield return new WaitForSeconds(typeWriterWaitTime);
155167
}
156168

Scripts/Samples/BasicExample/DialogueGraph.asset

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MonoBehaviour:
1313
m_Name: Text
1414
m_EditorClassIdentifier:
1515
graph: {fileID: 11400000}
16-
position: {x: 1558.5032, y: 160.4265}
16+
position: {x: 1560, y: 120}
1717
ports:
1818
keys:
1919
- input
@@ -43,7 +43,7 @@ MonoBehaviour:
4343
_connectionType: 0
4444
_typeConstraint: 0
4545
_dynamic: 0
46-
id: 7c8d49ec09cb78b49acc508dd5640f54
46+
id: 2ec36adb3183cab4eb23d695af27123f
4747
nodeName: Text node
4848
processed: 0
4949
entered: 0
@@ -104,10 +104,10 @@ MonoBehaviour:
104104
_connectionType: 0
105105
_typeConstraint: 0
106106
_dynamic: 0
107-
id: 898496b82ad93154c8383ad7a671a2ac
107+
id: 4078b5f52e5d8d74ebbdac1d559ce374
108108
nodeName: Text node
109109
processed: 0
110-
entered: 0
110+
entered: 1
111111
input: 0
112112
metaData:
113113
- key: Speaker
@@ -116,9 +116,9 @@ MonoBehaviour:
116116
value:
117117
audioClip: {fileID: 0}
118118
syncTypewriter: 0
119-
text: ' {"effect":"wave", "text":"this"} {"effect":"wave", "text":"is a"} {"effect":"bounce",
120-
"text":" basic"} example on how to use the dialogue system! Press Space to advance
121-
the dialogue.'
119+
text: ' {"effect":"wave", "text":"<test/>"} {"effect":"wave", "text":"is a"} {"effect":"bounce",
120+
"text":" basic"} <test/> on how to use the %1/%WAIT %2/%WAIT %3/%WAIT dialogue
121+
system! Press Space to advance the dialogue.'
122122
WaitForInput: 1
123123
output: 0
124124
--- !u!114 &-5703039246456782174
@@ -164,7 +164,7 @@ MonoBehaviour:
164164
_connectionType: 0
165165
_typeConstraint: 0
166166
_dynamic: 0
167-
id: 892bd11b00974c74f843cbd703ff7bed
167+
id: 82add2d35d5460f4db46c890527321c7
168168
nodeName: Text node
169169
processed: 0
170170
entered: 0
@@ -209,10 +209,10 @@ MonoBehaviour:
209209
_connectionType: 0
210210
_typeConstraint: 0
211211
_dynamic: 0
212-
id: 035c20f40a456da40a0cbbd9dcb026b5
212+
id: 29ae97534f649e94c8af9cc8d23a26b0
213213
nodeName: Branch
214-
processed: 0
215-
entered: 0
214+
processed: 1
215+
entered: 1
216216
output: 0
217217
branchCondition: []
218218
--- !u!114 &11400000
@@ -296,7 +296,7 @@ MonoBehaviour:
296296
_connectionType: 0
297297
_typeConstraint: 0
298298
_dynamic: 0
299-
id: 6e5ecd46306aa8941ad8d9b3962178ce
299+
id: aa3e4cb6207c4ce4aafe43f3a873ec77
300300
nodeName: Text node
301301
processed: 0
302302
entered: 0
@@ -372,7 +372,7 @@ MonoBehaviour:
372372
_connectionType: 0
373373
_typeConstraint: 0
374374
_dynamic: 1
375-
id: 1af10f4a788ac234da359833a8552363
375+
id: ceaf9ed0e136a3942a8f11b63e797501
376376
nodeName: Choice Node
377377
processed: 0
378378
entered: 0
@@ -428,7 +428,7 @@ MonoBehaviour:
428428
_connectionType: 0
429429
_typeConstraint: 0
430430
_dynamic: 0
431-
id: eeb131cd58988f242a884c83493ecf1f
431+
id: 0036498c11fbdbc4eaccd21e89ab1072
432432
nodeName: Text node
433433
processed: 0
434434
entered: 0
@@ -488,7 +488,7 @@ MonoBehaviour:
488488
_connectionType: 0
489489
_typeConstraint: 0
490490
_dynamic: 0
491-
id: b78dabeac835e8a4a81bef9b93187135
491+
id: 8fcf86c93e9ffe84683b88e4dadc1d33
492492
nodeName: Text node
493493
processed: 0
494494
entered: 0
@@ -549,7 +549,7 @@ MonoBehaviour:
549549
_connectionType: 0
550550
_typeConstraint: 0
551551
_dynamic: 0
552-
id: c4597caa8fd9a6c48ad1ae4b35b52c7a
552+
id: 832f5d28bd47df6428f96d13fed54e53
553553
nodeName: Text node
554554
processed: 0
555555
entered: 0
@@ -620,7 +620,7 @@ MonoBehaviour:
620620
_connectionType: 0
621621
_typeConstraint: 0
622622
_dynamic: 0
623-
id: 16d99c74cb287044185928e315bf4ba5
623+
id: abeb8af89ce4cbc4d85074970ab91c1d
624624
nodeName: Condition
625625
processed: 0
626626
entered: 0
@@ -680,7 +680,7 @@ MonoBehaviour:
680680
_connectionType: 0
681681
_typeConstraint: 0
682682
_dynamic: 0
683-
id: 08ba2cfc30af39948abbd92428d1ff1c
683+
id: bdb6def685dd7a24293acf48c84861ab
684684
nodeName: Event node
685685
processed: 0
686686
entered: 0

0 commit comments

Comments
 (0)