You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.1 KiB
110 lines
2.1 KiB
10 years ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
10 years ago
|
using System.Collections.Generic;
|
||
10 years ago
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
|
|
||
|
public class SayDialog : Dialog
|
||
|
{
|
||
10 years ago
|
// Currently active Say Dialog used to display Say text
|
||
|
public static SayDialog activeSayDialog;
|
||
10 years ago
|
|
||
10 years ago
|
public Image continueImage;
|
||
10 years ago
|
public AudioClip continueSound;
|
||
10 years ago
|
|
||
10 years ago
|
public static SayDialog GetSayDialog()
|
||
10 years ago
|
{
|
||
10 years ago
|
if (activeSayDialog == null)
|
||
10 years ago
|
{
|
||
10 years ago
|
// Use first Say Dialog found in the scene (if any)
|
||
|
SayDialog sd = GameObject.FindObjectOfType<SayDialog>();
|
||
|
if (sd != null)
|
||
|
{
|
||
|
activeSayDialog = sd;
|
||
|
}
|
||
|
|
||
|
if (activeSayDialog == null)
|
||
|
{
|
||
|
// Auto spawn a say dialog object from the prefab
|
||
10 years ago
|
GameObject prefab = Resources.Load<GameObject>("SayDialog");
|
||
|
if (prefab != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
GameObject go = Instantiate(prefab) as GameObject;
|
||
|
go.SetActive(false);
|
||
|
go.name = "SayDialog";
|
||
|
activeSayDialog = go.GetComponent<SayDialog>();
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
return activeSayDialog;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual void Say(string text, bool waitForInput, Action onComplete)
|
||
10 years ago
|
{
|
||
|
Clear();
|
||
10 years ago
|
|
||
|
Action onWritingComplete = delegate {
|
||
10 years ago
|
if (waitForInput)
|
||
|
{
|
||
|
ShowContinueImage(true);
|
||
|
StartCoroutine(WaitForInput(delegate {
|
||
10 years ago
|
|
||
|
if (continueSound != null)
|
||
|
{
|
||
|
AudioSource.PlayClipAtPoint(continueSound, Vector3.zero);
|
||
|
}
|
||
10 years ago
|
Clear();
|
||
|
StopVoiceOver();
|
||
|
if (onComplete != null)
|
||
|
{
|
||
|
onComplete();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
10 years ago
|
if (onComplete != null)
|
||
|
{
|
||
|
onComplete();
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
};
|
||
|
|
||
|
Action onExitTag = delegate {
|
||
|
Clear();
|
||
|
if (onComplete != null)
|
||
|
{
|
||
|
onComplete();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
StartCoroutine(WriteText(text, onWritingComplete, onExitTag));
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public override void Clear()
|
||
10 years ago
|
{
|
||
|
base.Clear();
|
||
10 years ago
|
ShowContinueImage(false);
|
||
|
}
|
||
|
|
||
10 years ago
|
protected override void OnWaitForInputTag(bool waiting)
|
||
10 years ago
|
{
|
||
10 years ago
|
ShowContinueImage(waiting);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
protected virtual void ShowContinueImage(bool visible)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (continueImage != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
continueImage.enabled = visible;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|