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.
166 lines
3.8 KiB
166 lines
3.8 KiB
10 years ago
|
using UnityEngine;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
10 years ago
|
[CommandInfo("Dialog",
|
||
|
"Say",
|
||
10 years ago
|
"Writes text in a dialog box.")]
|
||
10 years ago
|
[AddComponentMenu("")]
|
||
10 years ago
|
public class Say : Command
|
||
10 years ago
|
{
|
||
10 years ago
|
[TextArea(5,10)]
|
||
10 years ago
|
public string storyText;
|
||
10 years ago
|
|
||
10 years ago
|
[Tooltip("Character that is speaking")]
|
||
10 years ago
|
public Character character;
|
||
10 years ago
|
|
||
10 years ago
|
[Tooltip("Portrait that represents speaking character")]
|
||
|
public Sprite portrait;
|
||
|
|
||
10 years ago
|
[Tooltip("Voiceover audio to play when writing the text")]
|
||
10 years ago
|
public AudioClip voiceOverClip;
|
||
10 years ago
|
|
||
10 years ago
|
[Tooltip("Always show this Say text when the command is executed multiple times")]
|
||
|
public bool showAlways = true;
|
||
|
|
||
|
[Tooltip("Number of times to show this Say text when the command is executed multiple times")]
|
||
|
public int showCount = 1;
|
||
10 years ago
|
|
||
10 years ago
|
[Tooltip("Type this text in the previous dialog box.")]
|
||
|
public bool extendPrevious = false;
|
||
|
|
||
|
[Tooltip("Fade in this dialog box.")]
|
||
|
public bool fadeIn = false;
|
||
|
|
||
|
[Tooltip("Fade out this dialog box.")]
|
||
|
public bool fadeOut = false;
|
||
|
|
||
|
[Tooltip("Wait for player to click before hiding the dialog and continuing. If false then the dialog will display and execution will continue immediately.")]
|
||
|
public bool waitForClick = 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.")]
|
||
|
public SayDialog setSayDialog;
|
||
10 years ago
|
|
||
10 years ago
|
protected int executionCount;
|
||
10 years ago
|
|
||
10 years ago
|
public override void OnEnter()
|
||
10 years ago
|
{
|
||
10 years ago
|
if (!showAlways && executionCount >= showCount)
|
||
10 years ago
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
executionCount++;
|
||
10 years ago
|
|
||
10 years ago
|
// Override the active say dialog if needed
|
||
|
if (setSayDialog != null)
|
||
|
{
|
||
|
SayDialog.activeSayDialog = setSayDialog;
|
||
|
}
|
||
|
|
||
|
SayDialog sayDialog = SayDialog.GetSayDialog();
|
||
10 years ago
|
|
||
10 years ago
|
if (sayDialog == null)
|
||
10 years ago
|
{
|
||
10 years ago
|
Continue();
|
||
|
return;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
FungusScript fungusScript = GetFungusScript();
|
||
|
sayDialog.SetCharacter(character, fungusScript);
|
||
10 years ago
|
sayDialog.SetCharacterImage(portrait);
|
||
10 years ago
|
|
||
10 years ago
|
bool fadingIn = false;
|
||
|
bool movingIn = false;
|
||
|
if (sayDialog.alwaysFadeDialog || fadeIn)
|
||
|
{
|
||
|
sayDialog.FadeInDialog();
|
||
|
fadingIn = true;
|
||
|
}
|
||
|
if (sayDialog.alwaysMoveDialog)
|
||
|
{
|
||
|
sayDialog.MoveInDialog();
|
||
|
movingIn = true;
|
||
|
}
|
||
|
if (!fadingIn && !movingIn)
|
||
|
{
|
||
|
sayDialog.ShowDialog(true);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
if (voiceOverClip != null)
|
||
|
{
|
||
10 years ago
|
sayDialog.PlayVoiceOver(voiceOverClip);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (extendPrevious)
|
||
|
{
|
||
|
displayText = "{s=0}" + Dialog.prevStoryText + "{/s}" + displayText;
|
||
|
}
|
||
|
|
||
|
string subbedText = fungusScript.SubstituteVariables(displayText);
|
||
10 years ago
|
|
||
10 years ago
|
sayDialog.Say(subbedText, waitForClick, delegate {
|
||
|
if (waitForClick)
|
||
10 years ago
|
{
|
||
10 years ago
|
bool fadingOut = false;
|
||
|
bool movingOut = false;
|
||
|
if (sayDialog.alwaysFadeDialog || fadeOut)
|
||
|
{
|
||
|
sayDialog.FadeOutDialog();
|
||
|
fadingOut = true;
|
||
|
}
|
||
|
if (sayDialog.alwaysMoveDialog)
|
||
|
{
|
||
|
sayDialog.MoveOutDialog();
|
||
|
movingOut = true;
|
||
|
}
|
||
|
if (!fadingOut && !movingOut)
|
||
|
{
|
||
|
sayDialog.ShowDialog(false);
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
Continue();
|
||
|
});
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public override string GetSummary()
|
||
10 years ago
|
{
|
||
10 years ago
|
string namePrefix = "";
|
||
|
if (character != null)
|
||
|
{
|
||
|
namePrefix = character.nameText + ": ";
|
||
|
}
|
||
10 years ago
|
if (extendPrevious)
|
||
|
{
|
||
|
namePrefix = "EXTEND" + ": ";
|
||
|
}
|
||
10 years ago
|
return namePrefix + "\"" + storyText + "\"";
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(184, 210, 235, 255);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public override void OnReset()
|
||
|
{
|
||
|
executionCount = 0;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|