diff --git a/Assets/Fungus/Scripts/Commands/Write.cs b/Assets/Fungus/Scripts/Commands/Write.cs index eb0599f8..cd801621 100644 --- a/Assets/Fungus/Scripts/Commands/Write.cs +++ b/Assets/Fungus/Scripts/Commands/Write.cs @@ -51,9 +51,9 @@ namespace Fungus.Commands [SerializeField] protected ColorData setColor = new ColorData(Color.white); - protected IWriter GetWriter() + protected Writer GetWriter() { - IWriter writer = textObject.GetComponent(); + var writer = textObject.GetComponent(); if (writer == null) { writer = textObject.AddComponent(); @@ -70,7 +70,7 @@ namespace Fungus.Commands return; } - IWriter writer = GetWriter(); + var writer = GetWriter(); if (writer == null) { Continue(); diff --git a/Assets/Fungus/Scripts/Components/SayDialog.cs b/Assets/Fungus/Scripts/Components/SayDialog.cs index 221804d1..445d6386 100644 --- a/Assets/Fungus/Scripts/Components/SayDialog.cs +++ b/Assets/Fungus/Scripts/Components/SayDialog.cs @@ -40,7 +40,7 @@ namespace Fungus protected float startStoryTextInset; protected WriterAudio writerAudio; - protected IWriter writer; + protected Writer writer; protected CanvasGroup canvasGroup; protected bool fadeWhenDone = true; @@ -83,14 +83,14 @@ namespace Fungus return activeSayDialog; } - protected IWriter GetWriter() + protected Writer GetWriter() { if (writer != null) { return writer; } - writer = GetComponent(); + writer = GetComponent(); if (writer == null) { writer = gameObject.AddComponent(); @@ -406,7 +406,7 @@ namespace Fungus /// Callback to execute when writing and player input have finished. public virtual IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) { - IWriter writer = GetWriter(); + var writer = GetWriter(); if (writer.IsWriting || writer.IsWaitingForInput) { diff --git a/Assets/Fungus/Scripts/Components/Writer.cs b/Assets/Fungus/Scripts/Components/Writer.cs index 721d674c..4b82a4b7 100644 --- a/Assets/Fungus/Scripts/Components/Writer.cs +++ b/Assets/Fungus/Scripts/Components/Writer.cs @@ -15,7 +15,7 @@ namespace Fungus /// /// Writes text using a typewriter effect to a UI text object. /// - public class Writer : MonoBehaviour, IWriter, IDialogInputListener + public class Writer : MonoBehaviour, IDialogInputListener { [Tooltip("Gameobject containing a Text, Inout Field or Text Mesh object to write to")] [SerializeField] protected GameObject targetTextObject; @@ -180,28 +180,6 @@ namespace Fungus } } - public virtual bool HasTextObject() - { - return (textUI != null || inputField != null || textMesh != null || textComponent != null); - } - - public virtual bool SupportsRichText() - { - if (textUI != null) - { - return textUI.supportRichText; - } - if (inputField != null) - { - return false; - } - if (textMesh != null) - { - return textMesh.richText; - } - return false; - } - protected virtual void UpdateOpenMarkup() { openString.Length = 0; @@ -256,7 +234,7 @@ namespace Fungus } } - virtual protected bool CheckParamCount(List paramList, int count) + protected virtual bool CheckParamCount(List paramList, int count) { if (paramList == null) { @@ -571,7 +549,7 @@ namespace Fungus } } - protected void PartitionString(bool wholeWords, string inputString, int i) + protected virtual void PartitionString(bool wholeWords, string inputString, int i) { leftString.Length = 0; rightString.Length = 0; @@ -605,7 +583,7 @@ namespace Fungus } } - protected void ConcatenateString(string startText) + protected virtual void ConcatenateString(string startText) { outputString.Length = 0; @@ -625,11 +603,6 @@ namespace Fungus } } - public virtual string GetTagHelp() - { - return ""; - } - protected virtual IEnumerator DoWait(List paramList) { var param = ""; @@ -784,26 +757,21 @@ namespace Fungus } } - #region IDialogInputListener implementation - - public virtual void OnNextLineEvent() - { - inputFlag = true; - - if (isWriting) - { - NotifyInput(); - } - } - - #endregion - - #region IWriter implementation + #region Public methods + /// + /// This property is true when the writer is writing text or waiting (i.e. still processing tokens). + /// public virtual bool IsWriting { get { return isWriting; } } + /// + /// This property is true when the writer is waiting for user input to continue. + /// public virtual bool IsWaitingForInput { get { return isWaitingForInput; } } + /// + /// Stop writing text. + /// public virtual void Stop() { if (isWriting || isWaitingForInput) @@ -812,6 +780,15 @@ namespace Fungus } } + /// + /// Writes text using a typewriter effect to a UI text object. + /// + /// Text to be written + /// If true clears the previous text. + /// Writes the text and then waits for player input before calling onComplete. + /// Stops any currently playing audioclip. + /// Audio clip to play when text starts writing. + /// Callback to call when writing is finished. public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, Action onComplete) { if (clear) @@ -840,6 +817,9 @@ namespace Fungus yield return StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete)); } + /// + /// Sets the color property of the text UI object. + /// public virtual void SetTextColor(Color textColor) { if (textUI != null) @@ -859,6 +839,9 @@ namespace Fungus } } + /// + /// Sets the alpha component of the color property of the text UI object. + /// public virtual void SetTextAlpha(float textAlpha) { if (textUI != null) @@ -884,6 +867,48 @@ namespace Fungus } } + /// + /// Returns true if there is a supported text object attached to this writer. + /// + public virtual bool HasTextObject() + { + return (textUI != null || inputField != null || textMesh != null || textComponent != null); + } + + /// + /// Returns true if the text object has rich text support. + /// + public virtual bool SupportsRichText() + { + if (textUI != null) + { + return textUI.supportRichText; + } + if (inputField != null) + { + return false; + } + if (textMesh != null) + { + return textMesh.richText; + } + return false; + } + + #endregion + + #region IDialogInputListener implementation + + public virtual void OnNextLineEvent() + { + inputFlag = true; + + if (isWriting) + { + NotifyInput(); + } + } + #endregion } } diff --git a/Assets/Fungus/Scripts/Interfaces/IWriter.cs b/Assets/Fungus/Scripts/Interfaces/IWriter.cs index 62c18c67..c770570d 100644 --- a/Assets/Fungus/Scripts/Interfaces/IWriter.cs +++ b/Assets/Fungus/Scripts/Interfaces/IWriter.cs @@ -6,48 +6,6 @@ using System.Collections; namespace Fungus { - /// - /// Writes text using a typewriter effect to a UI text object. - /// - public interface IWriter - { - /// - /// This property is true when the writer is writing text or waiting (i.e. still processing tokens). - /// - bool IsWriting { get; } - - /// - /// This property is true when the writer is waiting for user input to continue. - /// - bool IsWaitingForInput { get; } - - /// - /// Stop writing text. - /// - void Stop(); - - /// - /// Writes text using a typewriter effect to a UI text object. - /// - /// Text to be written - /// If true clears the previous text. - /// Writes the text and then waits for player input before calling onComplete. - /// Stops any currently playing audioclip. - /// Audio clip to play when text starts writing. - /// Callback to call when writing is finished. - IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, System.Action onComplete); - - /// - /// Sets the color property of the text UI object. - /// - void SetTextColor(Color textColor); - - /// - /// Sets the alpha component of the color property of the text UI object. - /// - void SetTextAlpha(float textAlpha); - } - /// /// Implement this interface to be notified about Writer events. ///