diff --git a/Assets/Fungus/Dialog/Editor/SayEditor.cs b/Assets/Fungus/Dialog/Editor/SayEditor.cs index f8174e0c..2a1cc334 100644 --- a/Assets/Fungus/Dialog/Editor/SayEditor.cs +++ b/Assets/Fungus/Dialog/Editor/SayEditor.cs @@ -31,7 +31,7 @@ namespace Fungus.Script string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30)); bool displayOnce = EditorGUILayout.Toggle(new GUIContent("Display Once", "Display this text once and never show it again."), t.displayOnce); - + if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(t, "Set Say"); @@ -40,6 +40,17 @@ namespace Fungus.Script t.displayOnce = displayOnce; } + if (t.options.Count > 0) + { + float timeout = EditorGUILayout.FloatField(new GUIContent("Option Timeout", "Time limit for player to choose an option."), + t.timeoutDuration); + if (timeout != t.timeoutDuration) + { + Undo.RecordObject(t, "Set Timeout"); + t.timeoutDuration = timeout; + } + } + ReorderableListGUI.Title("Options"); ReorderableListGUI.ListField(optionListProperty); diff --git a/Assets/Fungus/Dialog/Scripts/Dialog.cs b/Assets/Fungus/Dialog/Scripts/Dialog.cs index 11b24e4a..aafc795c 100644 --- a/Assets/Fungus/Dialog/Scripts/Dialog.cs +++ b/Assets/Fungus/Dialog/Scripts/Dialog.cs @@ -22,6 +22,10 @@ namespace Fungus.Script public Action onSelect; } + public float writingSpeed; + public AudioClip writingSound; + public bool loopWritingSound = true; + public Canvas dialogCanvas; public List optionButtons = new List(); public Text nameText; @@ -129,9 +133,64 @@ namespace Fungus.Script IEnumerator WriteText(string text, Action onWritingComplete) { - if (storyText != null) + // Zero CPS means write instantly + // Also write instantly if text contains markup tags + if (writingSpeed == 0 || + text.Contains("<")) { storyText.text = text; + if (onWritingComplete != null) + { + onWritingComplete(); + } + yield break; + } + + GameObject typingAudio = null; + + if (writingSound != null) + { + typingAudio = new GameObject("WritingSound"); + typingAudio.AddComponent(); + typingAudio.audio.clip = writingSound; + typingAudio.audio.loop = loopWritingSound; + typingAudio.audio.Play(); + } + + storyText.text = ""; + + // Make one character visible at a time + float writeDelay = (1f / (float)writingSpeed); + float timeAccumulator = 0f; + int i = 0; + + while (true) + { + timeAccumulator += Time.deltaTime; + + while (timeAccumulator > writeDelay) + { + i++; + timeAccumulator -= writeDelay; + } + + if (i >= text.Length) + { + storyText.text = text; + break; + } + else + { + string left = text.Substring(0, i + 1); + storyText.text = left; + } + + yield return null; + } + + if (typingAudio != null) + { + Destroy(typingAudio); } if (onWritingComplete != null) diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 6d5204d8..0f58687d 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ