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.
132 lines
4.4 KiB
132 lines
4.4 KiB
9 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
|
|
||
11 years ago
|
using UnityEngine;
|
||
10 years ago
|
using UnityEngine.Serialization;
|
||
11 years ago
|
using System.Collections.Generic;
|
||
10 years ago
|
using System;
|
||
11 years ago
|
|
||
11 years ago
|
namespace Fungus
|
||
11 years ago
|
{
|
||
9 years ago
|
/// <summary>
|
||
|
/// A Character that can be used in dialogue via the Say, Conversation and Portrait commands.
|
||
|
/// </summary>
|
||
9 years ago
|
[ExecuteInEditMode]
|
||
8 years ago
|
public class Character : MonoBehaviour, ICharacter, ILocalizable
|
||
9 years ago
|
{
|
||
8 years ago
|
[Tooltip("Character name as displayed in Say Dialog.")]
|
||
9 years ago
|
[SerializeField] protected string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad")
|
||
|
|
||
8 years ago
|
[Tooltip("Color to display the character name in Say Dialog.")]
|
||
9 years ago
|
[SerializeField] protected Color nameColor = Color.white;
|
||
|
|
||
8 years ago
|
[Tooltip("Sound effect to play when this character is speaking.")]
|
||
9 years ago
|
[SerializeField] protected AudioClip soundEffect;
|
||
|
|
||
8 years ago
|
[Tooltip("List of portrait images that can be displayed for this character.")]
|
||
9 years ago
|
[SerializeField] protected List<Sprite> portraits;
|
||
|
|
||
8 years ago
|
[Tooltip("Direction that portrait sprites face.")]
|
||
9 years ago
|
[SerializeField] protected FacingDirection portraitsFace;
|
||
|
|
||
8 years ago
|
[Tooltip("Sets the active Say dialog with a reference to a Say Dialog object in the scene. This Say Dialog will be used whenever the character speaks.")]
|
||
9 years ago
|
[SerializeField] protected SayDialog setSayDialog;
|
||
9 years ago
|
|
||
|
[FormerlySerializedAs("notes")]
|
||
|
[TextArea(5,10)]
|
||
9 years ago
|
[SerializeField] protected string description;
|
||
9 years ago
|
|
||
8 years ago
|
protected PortraitState portaitState = new PortraitState();
|
||
|
|
||
9 years ago
|
static public List<Character> activeCharacters = new List<Character>();
|
||
|
|
||
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
if (!activeCharacters.Contains(this))
|
||
|
{
|
||
|
activeCharacters.Add(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected virtual void OnDisable()
|
||
|
{
|
||
|
activeCharacters.Remove(this);
|
||
|
}
|
||
|
|
||
8 years ago
|
#region ICharacter implementation
|
||
9 years ago
|
|
||
8 years ago
|
public virtual string NameText { get { return nameText; } }
|
||
9 years ago
|
|
||
8 years ago
|
public virtual Color NameColor { get { return nameColor; } }
|
||
|
|
||
|
public virtual AudioClip SoundEffect { get { return soundEffect; } }
|
||
|
|
||
|
public virtual Sprite ProfileSprite { get; set; }
|
||
9 years ago
|
|
||
8 years ago
|
public virtual List<Sprite> Portraits { get { return portraits; } }
|
||
|
|
||
|
public virtual FacingDirection PortraitsFace { get { return portraitsFace; } }
|
||
|
|
||
|
public virtual PortraitState State { get { return portaitState; } }
|
||
|
|
||
|
public virtual ISayDialog SetSayDialog { get { return setSayDialog; } }
|
||
|
|
||
|
/// <summary>
|
||
|
/// Returns true if the character name starts with the specified string. Case insensitive.
|
||
|
/// </summary>
|
||
9 years ago
|
public bool NameStartsWith(string matchString)
|
||
|
{
|
||
|
return name.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture)
|
||
|
|| nameText.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Looks for a portrait by name on a character
|
||
|
/// If none is found, give a warning and return a blank sprite
|
||
|
/// </summary>
|
||
8 years ago
|
public virtual Sprite GetPortrait(string portraitString)
|
||
9 years ago
|
{
|
||
8 years ago
|
if (String.IsNullOrEmpty(portraitString))
|
||
9 years ago
|
{
|
||
9 years ago
|
return null;
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
for (int i = 0; i < portraits.Count; i++)
|
||
9 years ago
|
{
|
||
8 years ago
|
if (portraits[i] != null && String.Compare(portraits[i].name, portraitString, true) == 0)
|
||
9 years ago
|
{
|
||
9 years ago
|
return portraits[i];
|
||
9 years ago
|
}
|
||
|
}
|
||
9 years ago
|
return null;
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
#endregion
|
||
|
|
||
|
#region ILocalizable implementation
|
||
|
|
||
|
public virtual string GetStandardText()
|
||
|
{
|
||
|
return nameText;
|
||
|
}
|
||
|
|
||
|
public virtual void SetStandardText(string standardText)
|
||
|
{
|
||
|
nameText = standardText;
|
||
|
}
|
||
|
|
||
9 years ago
|
public virtual string GetDescription()
|
||
|
{
|
||
|
return description;
|
||
|
}
|
||
|
|
||
|
public virtual string GetStringId()
|
||
|
{
|
||
|
// String id for character names is CHARACTER.<Character Name>
|
||
|
return "CHARACTER." + nameText;
|
||
|
}
|
||
9 years ago
|
|
||
|
#endregion
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|