Browse Source

Continue image displays when waiting for user input

Say Dialog sets to 0 alpha at start
master
chrisgregan 10 years ago
parent
commit
11fa2a6eaa
  1. 31
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  2. 15
      Assets/Fungus/UI/Scripts/Writer.cs

31
Assets/Fungus/Narrative/Scripts/SayDialog.cs

@ -15,6 +15,8 @@ namespace Fungus
public Image continueImage; public Image continueImage;
public AudioClip continueSound; public AudioClip continueSound;
protected Writer writer;
public static SayDialog GetSayDialog() public static SayDialog GetSayDialog()
{ {
if (activeSayDialog == null) if (activeSayDialog == null)
@ -43,41 +45,38 @@ namespace Fungus
return activeSayDialog; return activeSayDialog;
} }
protected virtual void Start() protected Writer GetWriter()
{ {
CanvasGroup canvasGroup = dialogCanvas.GetComponent<CanvasGroup>(); if (writer != null)
canvasGroup.alpha = 0f; {
return writer;
} }
public virtual void Say(string text, bool clearPrevious, bool waitForInput, AudioClip voiceOverClip, Action onComplete) writer = GetComponent<Writer>();
{
Writer writer = GetComponent<Writer>();
if (writer == null) if (writer == null)
{ {
writer = gameObject.AddComponent<Writer>(); writer = gameObject.AddComponent<Writer>();
} }
ShowContinueImage(false); return writer;
writer.Write(text, clearPrevious, waitForInput, onComplete);
} }
public override void Clear() protected virtual void Start()
{ {
base.Clear(); CanvasGroup canvasGroup = dialogCanvas.GetComponent<CanvasGroup>();
ShowContinueImage(false); canvasGroup.alpha = 0f;
} }
protected virtual void OnWaitForInputTag(bool waiting) public virtual void Say(string text, bool clearPrevious, bool waitForInput, AudioClip voiceOverClip, Action onComplete)
{ {
ShowContinueImage(waiting); GetWriter().Write(text, clearPrevious, waitForInput, onComplete);
} }
protected virtual void ShowContinueImage(bool visible) protected virtual void Update()
{ {
if (continueImage != null) if (continueImage != null)
{ {
continueImage.enabled = visible; continueImage.enabled = GetWriter().isWaitingForInput;
} }
} }
} }

15
Assets/Fungus/UI/Scripts/Writer.cs

@ -9,12 +9,25 @@ namespace Fungus
public class Writer : MonoBehaviour, IDialogInputListener public class Writer : MonoBehaviour, IDialogInputListener
{ {
[Tooltip("Gameobject containing a Text, Inout Field or Text Mesh object to write to")]
public GameObject targetTextObject; public GameObject targetTextObject;
[Tooltip("Writing characters per second")]
public float writingSpeed = 60; public float writingSpeed = 60;
[Tooltip("Pause duration for punctuation characters")]
public float punctuationPause = 0.25f; public float punctuationPause = 0.25f;
[Tooltip("Color of text that has not been revealed yet")]
public Color hiddenTextColor = new Color(1,1,1,0); public Color hiddenTextColor = new Color(1,1,1,0);
[Tooltip("Write one word at a time rather one character at a time")]
public bool writeWholeWords = false; public bool writeWholeWords = false;
// This property is true when the writer is waiting for user input to continue
[System.NonSerialized]
public bool isWaitingForInput;
protected float currentWritingSpeed; protected float currentWritingSpeed;
protected float currentPunctuationPause; protected float currentPunctuationPause;
protected Text textUI; protected Text textUI;
@ -498,10 +511,12 @@ namespace Fungus
protected virtual IEnumerator DoWaitForInput(bool clear) protected virtual IEnumerator DoWaitForInput(bool clear)
{ {
isWaitingForInput = true;
while (!inputFlag) while (!inputFlag)
{ {
yield return null; yield return null;
} }
isWaitingForInput = false;
inputFlag = false; inputFlag = false;

Loading…
Cancel
Save