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.
146 lines
3.2 KiB
146 lines
3.2 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 a line of story text to a Say Dialog. " +
|
||
|
"Select [Game Object > Fungus > Dialog > Say Dialog] to create a new Say Dialog in your scene. " +
|
||
|
"Select [Game Object > Fungus > Dialog > Character] to create a new selectable speaking character.")]
|
||
10 years ago
|
public class Say : Command
|
||
10 years ago
|
{
|
||
10 years ago
|
[Tooltip("Story text to display to the player")]
|
||
10 years ago
|
[TextArea(5,10)]
|
||
10 years ago
|
public string storyText;
|
||
10 years ago
|
|
||
10 years ago
|
[Tooltip("Speaking character to use when writing the story text")]
|
||
10 years ago
|
public Character character;
|
||
10 years ago
|
|
||
|
[Tooltip("Say Dialog to use when writing the story text.")]
|
||
10 years ago
|
public SayDialog sayDialog;
|
||
10 years ago
|
|
||
|
[Tooltip("Voiceover audio to play when writing the story text")]
|
||
10 years ago
|
public AudioClip voiceOverClip;
|
||
10 years ago
|
|
||
|
[Tooltip("Only show this text once, even if the command is executed again")]
|
||
10 years ago
|
public bool showOnce;
|
||
10 years ago
|
|
||
10 years ago
|
protected int executionCount;
|
||
10 years ago
|
|
||
10 years ago
|
protected bool showBasicGUI;
|
||
10 years ago
|
|
||
10 years ago
|
public override void OnEnter()
|
||
10 years ago
|
{
|
||
10 years ago
|
if (showOnce && executionCount > 0)
|
||
10 years ago
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
executionCount++;
|
||
10 years ago
|
|
||
10 years ago
|
showBasicGUI = false;
|
||
10 years ago
|
if (sayDialog == null)
|
||
10 years ago
|
{
|
||
10 years ago
|
// Try to get any SayDialog in the scene
|
||
10 years ago
|
sayDialog = GameObject.FindObjectOfType<SayDialog>();
|
||
|
if (sayDialog == null)
|
||
10 years ago
|
{
|
||
|
showBasicGUI = true;
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
sayDialog.SetCharacter(character);
|
||
10 years ago
|
|
||
10 years ago
|
sayDialog.ShowDialog(true);
|
||
10 years ago
|
|
||
10 years ago
|
if (voiceOverClip != null)
|
||
|
{
|
||
|
MusicController.GetInstance().PlaySound(voiceOverClip, 1f);
|
||
|
}
|
||
|
|
||
10 years ago
|
sayDialog.Say(storyText, delegate {
|
||
|
sayDialog.ShowDialog(false);
|
||
10 years ago
|
Continue();
|
||
|
});
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public override string GetSummary()
|
||
10 years ago
|
{
|
||
10 years ago
|
return "\"" + storyText + "\"";
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
protected virtual void OnGUI()
|
||
10 years ago
|
{
|
||
|
if (!showBasicGUI)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Draw a basic GUI to use when no uGUI dialog has been set
|
||
|
// Does not support drawing character images
|
||
|
|
||
|
GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
|
||
|
GUILayout.FlexibleSpace();
|
||
|
|
||
|
GUILayout.BeginVertical(GUILayout.Height(Screen.height));
|
||
|
GUILayout.FlexibleSpace();
|
||
|
|
||
|
GUILayout.BeginVertical(new GUIStyle(GUI.skin.box));
|
||
|
|
||
|
if (character != null)
|
||
|
{
|
||
10 years ago
|
GUILayout.Label(character.nameText);
|
||
10 years ago
|
GUILayout.Space(10);
|
||
|
}
|
||
|
|
||
|
GUILayout.Label(storyText);
|
||
|
if (GUILayout.Button("Continue"))
|
||
|
{
|
||
|
showBasicGUI = false;
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
GUILayout.EndVertical();
|
||
|
|
||
|
GUILayout.FlexibleSpace();
|
||
|
GUILayout.EndVertical();
|
||
|
|
||
|
GUILayout.FlexibleSpace();
|
||
|
GUILayout.EndHorizontal();
|
||
|
}
|
||
10 years ago
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(184, 210, 235, 255);
|
||
|
}
|
||
10 years ago
|
|
||
|
public override void OnCommandAdded(Sequence parentSequence)
|
||
|
{
|
||
|
// Find last Say command in the sequence, then copy the Say dialog it's using.
|
||
|
// This saves a step when adding a new Say command
|
||
|
for (int i = parentSequence.commandList.Count - 1; i >= 0; --i)
|
||
|
{
|
||
|
Say sayCommand = parentSequence.commandList[i] as Say;
|
||
|
if (sayCommand != null)
|
||
|
{
|
||
|
if (sayCommand.sayDialog != null)
|
||
|
{
|
||
|
sayDialog = sayCommand.sayDialog;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
public override void OnReset()
|
||
|
{
|
||
|
executionCount = 0;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|