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.
178 lines
5.7 KiB
178 lines
5.7 KiB
// 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) |
|
|
|
using UnityEngine; |
|
|
|
namespace Fungus.Commands |
|
{ |
|
/// <summary> |
|
/// Writes text in a dialog box. |
|
/// </summary> |
|
[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)] |
|
[SerializeField] protected string storyText = ""; |
|
|
|
[Tooltip("Notes about this story text for other authors, localization, etc.")] |
|
[SerializeField] protected string description = ""; |
|
|
|
[Tooltip("Character that is speaking")] |
|
[SerializeField] protected Character character; |
|
public virtual Character _Character { get { return character; } } |
|
|
|
[Tooltip("Portrait that represents speaking character")] |
|
[SerializeField] protected Sprite portrait; |
|
public virtual Sprite Portrait { get { return portrait; } set { portrait = value; } } |
|
|
|
[Tooltip("Voiceover audio to play when writing the text")] |
|
[SerializeField] protected AudioClip voiceOverClip; |
|
|
|
[Tooltip("Always show this Say text when the command is executed multiple times")] |
|
[SerializeField] protected bool showAlways = true; |
|
|
|
[Tooltip("Number of times to show this Say text when the command is executed multiple times")] |
|
[SerializeField] protected int showCount = 1; |
|
|
|
[Tooltip("Type this text in the previous dialog box.")] |
|
[SerializeField] protected bool extendPrevious = false; |
|
public virtual bool ExtendPrevious { get { return extendPrevious; } } |
|
|
|
[Tooltip("Fade out the dialog box when writing has finished and not waiting for input.")] |
|
[SerializeField] protected bool fadeWhenDone = true; |
|
|
|
[Tooltip("Wait for player to click before continuing.")] |
|
[SerializeField] protected bool waitForClick = true; |
|
|
|
[Tooltip("Stop playing voiceover when text finishes writing.")] |
|
[SerializeField] protected bool stopVoiceover = true; |
|
|
|
[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.")] |
|
[SerializeField] protected SayDialog setSayDialog; |
|
|
|
protected int executionCount; |
|
|
|
public override void OnEnter() |
|
{ |
|
if (!showAlways && executionCount >= showCount) |
|
{ |
|
Continue(); |
|
return; |
|
} |
|
|
|
executionCount++; |
|
|
|
// Override the active say dialog if needed |
|
if (character != null && character.SetSayDialog != null) |
|
{ |
|
SayDialog.activeSayDialog = character.SetSayDialog; |
|
} |
|
|
|
if (setSayDialog != null) |
|
{ |
|
SayDialog.activeSayDialog = setSayDialog; |
|
} |
|
|
|
var sayDialog = SayDialog.GetSayDialog(); |
|
if (sayDialog == null) |
|
{ |
|
Continue(); |
|
return; |
|
} |
|
|
|
var flowchart = GetFlowchart(); |
|
|
|
sayDialog.SetActive(true); |
|
|
|
sayDialog.SetCharacter(character, flowchart); |
|
sayDialog.SetCharacterImage(portrait); |
|
|
|
string displayText = storyText; |
|
|
|
foreach (CustomTag ct in CustomTag.activeCustomTags) |
|
{ |
|
displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith); |
|
if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "") |
|
{ |
|
displayText = displayText.Replace(ct.TagEndSymbol, ct.ReplaceTagEndWith); |
|
} |
|
} |
|
|
|
string subbedText = flowchart.SubstituteVariables(displayText); |
|
|
|
sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, stopVoiceover, voiceOverClip, delegate { |
|
Continue(); |
|
}); |
|
} |
|
|
|
public override string GetSummary() |
|
{ |
|
string namePrefix = ""; |
|
if (character != null) |
|
{ |
|
namePrefix = character.NameText + ": "; |
|
} |
|
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() |
|
{ |
|
var sayDialog = SayDialog.GetSayDialog(); |
|
if (sayDialog == null) |
|
{ |
|
return; |
|
} |
|
|
|
sayDialog.Stop(); |
|
} |
|
|
|
#region ILocalizable implementation |
|
|
|
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) |
|
{ |
|
stringId += character.NameText; |
|
} |
|
|
|
return stringId; |
|
} |
|
|
|
#endregion |
|
} |
|
} |