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.
179 lines
5.7 KiB
179 lines
5.7 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Writes text in a dialog box.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Narrative",
|
||
|
"Say",
|
||
|
"Writes text in a dialog box.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class Say : Command, ILocalizable
|
||
|
{
|
||
|
// Removed this tooltip as users's reported it obscures the text box
|
||
|
[TextArea(5,10)]
|
||
8 years ago
|
[SerializeField] protected string storyText = "";
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Notes about this story text for other authors, localization, etc.")]
|
||
8 years ago
|
[SerializeField] protected string description = "";
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Character that is speaking")]
|
||
8 years ago
|
[SerializeField] protected Character character;
|
||
8 years ago
|
public virtual Character _Character { get { return character; } }
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Portrait that represents speaking character")]
|
||
8 years ago
|
[SerializeField] protected Sprite portrait;
|
||
8 years ago
|
public virtual Sprite Portrait { get { return portrait; } set { portrait = value; } }
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Voiceover audio to play when writing the text")]
|
||
8 years ago
|
[SerializeField] protected AudioClip voiceOverClip;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Always show this Say text when the command is executed multiple times")]
|
||
8 years ago
|
[SerializeField] protected bool showAlways = true;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Number of times to show this Say text when the command is executed multiple times")]
|
||
8 years ago
|
[SerializeField] protected int showCount = 1;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Type this text in the previous dialog box.")]
|
||
8 years ago
|
[SerializeField] protected bool extendPrevious = false;
|
||
8 years ago
|
public virtual bool ExtendPrevious { get { return extendPrevious; } }
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Fade out the dialog box when writing has finished and not waiting for input.")]
|
||
8 years ago
|
[SerializeField] protected bool fadeWhenDone = true;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Wait for player to click before continuing.")]
|
||
8 years ago
|
[SerializeField] protected bool waitForClick = true;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Stop playing voiceover when text finishes writing.")]
|
||
8 years ago
|
[SerializeField] protected bool stopVoiceover = true;
|
||
9 years ago
|
|
||
8 years ago
|
[Tooltip("Sets the active Say dialog with a reference to a Say Dialog object in the scene. All story text will now display using this Say Dialog.")]
|
||
8 years ago
|
[SerializeField] protected SayDialog setSayDialog;
|
||
10 years ago
|
|
||
8 years ago
|
protected int executionCount;
|
||
10 years ago
|
|
||
8 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
if (!showAlways && executionCount >= showCount)
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
executionCount++;
|
||
10 years ago
|
|
||
8 years ago
|
// Override the active say dialog if needed
|
||
8 years ago
|
if (character != null && character.SetSayDialog != null)
|
||
8 years ago
|
{
|
||
8 years ago
|
SayDialog.activeSayDialog = character.SetSayDialog;
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if (setSayDialog != null)
|
||
|
{
|
||
|
SayDialog.activeSayDialog = setSayDialog;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
ISayDialog sayDialog = SayDialog.GetSayDialog();
|
||
10 years ago
|
|
||
8 years ago
|
if (sayDialog == null)
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Flowchart flowchart = GetFlowchart();
|
||
10 years ago
|
|
||
8 years ago
|
sayDialog.SetActive(true);
|
||
10 years ago
|
|
||
8 years ago
|
sayDialog.SetCharacter(character, flowchart);
|
||
|
sayDialog.SetCharacterImage(portrait);
|
||
9 years ago
|
|
||
8 years ago
|
string displayText = storyText;
|
||
10 years ago
|
|
||
8 years ago
|
foreach (CustomTag ct in CustomTag.activeCustomTags)
|
||
|
{
|
||
8 years ago
|
displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith);
|
||
|
if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "")
|
||
8 years ago
|
{
|
||
8 years ago
|
displayText = displayText.Replace(ct.TagEndSymbol, ct.ReplaceTagEndWith);
|
||
8 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
string subbedText = flowchart.SubstituteVariables(displayText);
|
||
10 years ago
|
|
||
9 years ago
|
sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, stopVoiceover, voiceOverClip, delegate {
|
||
8 years ago
|
Continue();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
string namePrefix = "";
|
||
|
if (character != null)
|
||
|
{
|
||
8 years ago
|
namePrefix = character.NameText + ": ";
|
||
8 years ago
|
}
|
||
|
if (extendPrevious)
|
||
|
{
|
||
|
namePrefix = "EXTEND" + ": ";
|
||
|
}
|
||
|
return namePrefix + "\"" + storyText + "\"";
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(184, 210, 235, 255);
|
||
|
}
|
||
|
|
||
|
public override void OnReset()
|
||
|
{
|
||
|
executionCount = 0;
|
||
|
}
|
||
|
|
||
|
public override void OnStopExecuting()
|
||
|
{
|
||
8 years ago
|
ISayDialog sayDialog = SayDialog.GetSayDialog();
|
||
8 years ago
|
if (sayDialog == null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
sayDialog.Stop();
|
||
|
}
|
||
|
|
||
8 years ago
|
#region ILocalizable implementation
|
||
|
|
||
8 years ago
|
public virtual string GetStandardText()
|
||
|
{
|
||
|
return storyText;
|
||
|
}
|
||
|
|
||
|
public virtual void SetStandardText(string standardText)
|
||
|
{
|
||
|
storyText = standardText;
|
||
|
}
|
||
|
|
||
|
public virtual string GetDescription()
|
||
|
{
|
||
|
return description;
|
||
|
}
|
||
|
|
||
|
public virtual string GetStringId()
|
||
|
{
|
||
|
// String id for Say commands is SAY.<Localization Id>.<Command id>.[Character Name]
|
||
|
string stringId = "SAY." + GetFlowchartLocalizationId() + "." + itemId + ".";
|
||
|
if (character != null)
|
||
|
{
|
||
8 years ago
|
stringId += character.NameText;
|
||
8 years ago
|
}
|
||
|
|
||
|
return stringId;
|
||
|
}
|
||
8 years ago
|
|
||
|
#endregion
|
||
8 years ago
|
}
|
||
10 years ago
|
}
|