Browse Source

Continue image displays when waiting for user input

Say Dialog sets to 0 alpha at start
master
chrisgregan 9 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 AudioClip continueSound;
protected Writer writer;
public static SayDialog GetSayDialog()
{
if (activeSayDialog == null)
@ -43,41 +45,38 @@ namespace Fungus
return activeSayDialog;
}
protected virtual void Start()
protected Writer GetWriter()
{
CanvasGroup canvasGroup = dialogCanvas.GetComponent<CanvasGroup>();
canvasGroup.alpha = 0f;
if (writer != null)
{
return writer;
}
public virtual void Say(string text, bool clearPrevious, bool waitForInput, AudioClip voiceOverClip, Action onComplete)
{
Writer writer = GetComponent<Writer>();
writer = GetComponent<Writer>();
if (writer == null)
{
writer = gameObject.AddComponent<Writer>();
}
ShowContinueImage(false);
writer.Write(text, clearPrevious, waitForInput, onComplete);
return writer;
}
public override void Clear()
protected virtual void Start()
{
base.Clear();
ShowContinueImage(false);
CanvasGroup canvasGroup = dialogCanvas.GetComponent<CanvasGroup>();
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)
{
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
{
[Tooltip("Gameobject containing a Text, Inout Field or Text Mesh object to write to")]
public GameObject targetTextObject;
[Tooltip("Writing characters per second")]
public float writingSpeed = 60;
[Tooltip("Pause duration for punctuation characters")]
public float punctuationPause = 0.25f;
[Tooltip("Color of text that has not been revealed yet")]
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;
// This property is true when the writer is waiting for user input to continue
[System.NonSerialized]
public bool isWaitingForInput;
protected float currentWritingSpeed;
protected float currentPunctuationPause;
protected Text textUI;
@ -498,10 +511,12 @@ namespace Fungus
protected virtual IEnumerator DoWaitForInput(bool clear)
{
isWaitingForInput = true;
while (!inputFlag)
{
yield return null;
}
isWaitingForInput = false;
inputFlag = false;

Loading…
Cancel
Save