Browse Source

Reverted IWriter interface

master
Christopher 8 years ago
parent
commit
ec4d0967dc
  1. 6
      Assets/Fungus/Scripts/Commands/Write.cs
  2. 8
      Assets/Fungus/Scripts/Components/SayDialog.cs
  3. 117
      Assets/Fungus/Scripts/Components/Writer.cs
  4. 42
      Assets/Fungus/Scripts/Interfaces/IWriter.cs

6
Assets/Fungus/Scripts/Commands/Write.cs

@ -51,9 +51,9 @@ namespace Fungus.Commands
[SerializeField] protected ColorData setColor = new ColorData(Color.white); [SerializeField] protected ColorData setColor = new ColorData(Color.white);
protected IWriter GetWriter() protected Writer GetWriter()
{ {
IWriter writer = textObject.GetComponent<IWriter>(); var writer = textObject.GetComponent<Writer>();
if (writer == null) if (writer == null)
{ {
writer = textObject.AddComponent<Writer>(); writer = textObject.AddComponent<Writer>();
@ -70,7 +70,7 @@ namespace Fungus.Commands
return; return;
} }
IWriter writer = GetWriter(); var writer = GetWriter();
if (writer == null) if (writer == null)
{ {
Continue(); Continue();

8
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -40,7 +40,7 @@ namespace Fungus
protected float startStoryTextInset; protected float startStoryTextInset;
protected WriterAudio writerAudio; protected WriterAudio writerAudio;
protected IWriter writer; protected Writer writer;
protected CanvasGroup canvasGroup; protected CanvasGroup canvasGroup;
protected bool fadeWhenDone = true; protected bool fadeWhenDone = true;
@ -83,14 +83,14 @@ namespace Fungus
return activeSayDialog; return activeSayDialog;
} }
protected IWriter GetWriter() protected Writer GetWriter()
{ {
if (writer != null) if (writer != null)
{ {
return writer; return writer;
} }
writer = GetComponent<IWriter>(); writer = GetComponent<Writer>();
if (writer == null) if (writer == null)
{ {
writer = gameObject.AddComponent<Writer>(); writer = gameObject.AddComponent<Writer>();
@ -406,7 +406,7 @@ namespace Fungus
/// <param name="onComplete">Callback to execute when writing and player input have finished.</param> /// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
public virtual IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) 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) if (writer.IsWriting || writer.IsWaitingForInput)
{ {

117
Assets/Fungus/Scripts/Components/Writer.cs

@ -15,7 +15,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Writes text using a typewriter effect to a UI text object. /// Writes text using a typewriter effect to a UI text object.
/// </summary> /// </summary>
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")] [Tooltip("Gameobject containing a Text, Inout Field or Text Mesh object to write to")]
[SerializeField] protected GameObject targetTextObject; [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() protected virtual void UpdateOpenMarkup()
{ {
openString.Length = 0; openString.Length = 0;
@ -256,7 +234,7 @@ namespace Fungus
} }
} }
virtual protected bool CheckParamCount(List<string> paramList, int count) protected virtual bool CheckParamCount(List<string> paramList, int count)
{ {
if (paramList == null) 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; leftString.Length = 0;
rightString.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; outputString.Length = 0;
@ -625,11 +603,6 @@ namespace Fungus
} }
} }
public virtual string GetTagHelp()
{
return "";
}
protected virtual IEnumerator DoWait(List<string> paramList) protected virtual IEnumerator DoWait(List<string> paramList)
{ {
var param = ""; var param = "";
@ -784,26 +757,21 @@ namespace Fungus
} }
} }
#region IDialogInputListener implementation #region Public methods
public virtual void OnNextLineEvent()
{
inputFlag = true;
if (isWriting)
{
NotifyInput();
}
}
#endregion
#region IWriter implementation
/// <summary>
/// This property is true when the writer is writing text or waiting (i.e. still processing tokens).
/// </summary>
public virtual bool IsWriting { get { return isWriting; } } public virtual bool IsWriting { get { return isWriting; } }
/// <summary>
/// This property is true when the writer is waiting for user input to continue.
/// </summary>
public virtual bool IsWaitingForInput { get { return isWaitingForInput; } } public virtual bool IsWaitingForInput { get { return isWaitingForInput; } }
/// <summary>
/// Stop writing text.
/// </summary>
public virtual void Stop() public virtual void Stop()
{ {
if (isWriting || isWaitingForInput) if (isWriting || isWaitingForInput)
@ -812,6 +780,15 @@ namespace Fungus
} }
} }
/// <summary>
/// Writes text using a typewriter effect to a UI text object.
/// </summary>
/// <param name="content">Text to be written</param>
/// <param name="clear">If true clears the previous text.</param>
/// <param name="waitForInput">Writes the text and then waits for player input before calling onComplete.</param>
/// <param name="stopAudio">Stops any currently playing audioclip.</param>
/// <param name="audioClip">Audio clip to play when text starts writing.</param>
/// <param name="onComplete">Callback to call when writing is finished.</param>
public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, Action onComplete) public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, Action onComplete)
{ {
if (clear) if (clear)
@ -840,6 +817,9 @@ namespace Fungus
yield return StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete)); yield return StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete));
} }
/// <summary>
/// Sets the color property of the text UI object.
/// </summary>
public virtual void SetTextColor(Color textColor) public virtual void SetTextColor(Color textColor)
{ {
if (textUI != null) if (textUI != null)
@ -859,6 +839,9 @@ namespace Fungus
} }
} }
/// <summary>
/// Sets the alpha component of the color property of the text UI object.
/// </summary>
public virtual void SetTextAlpha(float textAlpha) public virtual void SetTextAlpha(float textAlpha)
{ {
if (textUI != null) if (textUI != null)
@ -884,6 +867,48 @@ namespace Fungus
} }
} }
/// <summary>
/// Returns true if there is a supported text object attached to this writer.
/// </summary>
public virtual bool HasTextObject()
{
return (textUI != null || inputField != null || textMesh != null || textComponent != null);
}
/// <summary>
/// Returns true if the text object has rich text support.
/// </summary>
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 #endregion
} }
} }

42
Assets/Fungus/Scripts/Interfaces/IWriter.cs

@ -6,48 +6,6 @@ using System.Collections;
namespace Fungus namespace Fungus
{ {
/// <summary>
/// Writes text using a typewriter effect to a UI text object.
/// </summary>
public interface IWriter
{
/// <summary>
/// This property is true when the writer is writing text or waiting (i.e. still processing tokens).
/// </summary>
bool IsWriting { get; }
/// <summary>
/// This property is true when the writer is waiting for user input to continue.
/// </summary>
bool IsWaitingForInput { get; }
/// <summary>
/// Stop writing text.
/// </summary>
void Stop();
/// <summary>
/// Writes text using a typewriter effect to a UI text object.
/// </summary>
/// <param name="content">Text to be written</param>
/// <param name="clear">If true clears the previous text.</param>
/// <param name="waitForInput">Writes the text and then waits for player input before calling onComplete.</param>
/// <param name="stopAudio">Stops any currently playing audioclip.</param>
/// <param name="audioClip">Audio clip to play when text starts writing.</param>
/// <param name="onComplete">Callback to call when writing is finished.</param>
IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, System.Action onComplete);
/// <summary>
/// Sets the color property of the text UI object.
/// </summary>
void SetTextColor(Color textColor);
/// <summary>
/// Sets the alpha component of the color property of the text UI object.
/// </summary>
void SetTextAlpha(float textAlpha);
}
/// <summary> /// <summary>
/// Implement this interface to be notified about Writer events. /// Implement this interface to be notified about Writer events.
/// </summary> /// </summary>

Loading…
Cancel
Save