Browse Source

Refactored Character to use ICharacter interface

master
Christopher 9 years ago
parent
commit
2f2fd5128f
  1. 72
      Assets/Fungus/Narrative/Scripts/Character.cs
  2. 66
      Assets/Fungus/Narrative/Scripts/ICharacter.cs
  3. 12
      Assets/Fungus/Narrative/Scripts/ICharacter.cs.meta

72
Assets/Fungus/Narrative/Scripts/Character.cs

@ -12,37 +12,32 @@ namespace Fungus
/// A Character that can be used in dialogue via the Say, Conversation and Portrait commands. /// A Character that can be used in dialogue via the Say, Conversation and Portrait commands.
/// </summary> /// </summary>
[ExecuteInEditMode] [ExecuteInEditMode]
public class Character : MonoBehaviour, ILocalizable public class Character : MonoBehaviour, ICharacter, ILocalizable
{ {
[Tooltip("Character name as displayed in Say Dialog.")]
[SerializeField] protected string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad") [SerializeField] protected string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad")
public virtual string NameText { get { return nameText; } }
[Tooltip("Color to display the character name in Say Dialog.")]
[SerializeField] protected Color nameColor = Color.white; [SerializeField] protected Color nameColor = Color.white;
public virtual Color NameColor { get { return nameColor; } }
[Tooltip("Sound effect to play when this character is speaking.")]
[SerializeField] protected AudioClip soundEffect; [SerializeField] protected AudioClip soundEffect;
public virtual AudioClip SoundEffect { get { return soundEffect; } }
[SerializeField] protected Sprite profileSprite;
public virtual Sprite ProfileSprite { get { return profileSprite; } set { profileSprite = value; } }
[Tooltip("List of portrait images that can be displayed for this character.")]
[SerializeField] protected List<Sprite> portraits; [SerializeField] protected List<Sprite> portraits;
public virtual List<Sprite> Portraits { get { return portraits; } }
[Tooltip("Direction that portrait sprites face.")]
[SerializeField] protected FacingDirection portraitsFace; [SerializeField] protected FacingDirection portraitsFace;
public virtual FacingDirection PortraitsFace { get { return portraitsFace; } }
[SerializeField] protected PortraitState state = new PortraitState(); [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.")]
public virtual PortraitState State { get { return state; } }
[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; [SerializeField] protected SayDialog setSayDialog;
public virtual ISayDialog SetSayDialog { get { return setSayDialog; } }
[FormerlySerializedAs("notes")] [FormerlySerializedAs("notes")]
[TextArea(5,10)] [TextArea(5,10)]
[SerializeField] protected string description; [SerializeField] protected string description;
protected PortraitState portaitState = new PortraitState();
static public List<Character> activeCharacters = new List<Character>(); static public List<Character> activeCharacters = new List<Character>();
protected virtual void OnEnable() protected virtual void OnEnable()
@ -58,18 +53,27 @@ namespace Fungus
activeCharacters.Remove(this); activeCharacters.Remove(this);
} }
#region ILocalizable implementation #region ICharacter implementation
public virtual string GetStandardText() public virtual string NameText { get { return nameText; } }
{
return nameText;
}
public virtual void SetStandardText(string standardText) public virtual Color NameColor { get { return nameColor; } }
{
nameText = standardText; public virtual AudioClip SoundEffect { get { return soundEffect; } }
}
public virtual Sprite ProfileSprite { get; set; }
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>
public bool NameStartsWith(string matchString) public bool NameStartsWith(string matchString)
{ {
return name.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture) return name.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture)
@ -80,18 +84,16 @@ namespace Fungus
/// Looks for a portrait by name on a character /// Looks for a portrait by name on a character
/// If none is found, give a warning and return a blank sprite /// If none is found, give a warning and return a blank sprite
/// </summary> /// </summary>
/// <param name="portrait_string"></param> public virtual Sprite GetPortrait(string portraitString)
/// <returns>Character portrait sprite</returns>
public virtual Sprite GetPortrait(string portrait_string)
{ {
if (String.IsNullOrEmpty(portrait_string)) if (String.IsNullOrEmpty(portraitString))
{ {
return null; return null;
} }
for (int i = 0; i < portraits.Count; i++) for (int i = 0; i < portraits.Count; i++)
{ {
if (portraits[i] != null && String.Compare(portraits[i].name, portrait_string, true) == 0) if (portraits[i] != null && String.Compare(portraits[i].name, portraitString, true) == 0)
{ {
return portraits[i]; return portraits[i];
} }
@ -99,6 +101,20 @@ namespace Fungus
return null; return null;
} }
#endregion
#region ILocalizable implementation
public virtual string GetStandardText()
{
return nameText;
}
public virtual void SetStandardText(string standardText)
{
nameText = standardText;
}
public virtual string GetDescription() public virtual string GetDescription()
{ {
return description; return description;

66
Assets/Fungus/Narrative/Scripts/ICharacter.cs

@ -0,0 +1,66 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus
{
/// <summary>
/// A Character that can be used in dialogue via the Say, Conversation and Portrait commands.
/// </summary>
public interface ICharacter
{
/// <summary>
/// Character name as displayed in Say Dialog.
/// </summary>
string NameText { get; }
/// <summary>
/// Color to display the character name in Say Dialog.
/// </summary>
Color NameColor { get; }
/// <summary>
/// Sound effect to play when this character is speaking.
/// </summary>
/// <value>The sound effect.</value>
AudioClip SoundEffect { get; }
/// <summary>
/// List of portrait images that can be displayed for this character.
/// </summary>
List<Sprite> Portraits { get; }
/// <summary>
/// Direction that portrait sprites face.
/// </summary>
FacingDirection PortraitsFace { get; }
/// <summary>
/// Currently display profile sprite for this character.
/// </summary>
/// <value>The profile sprite.</value>
Sprite ProfileSprite { get; set; }
/// <summary>
/// Current display state of this character's portrait.
/// </summary>
/// <value>The state.</value>
PortraitState State { get; }
/// <summary>
/// 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.
/// </summary>
ISayDialog SetSayDialog { get; }
/// <summary>
/// Returns true if the character name starts with the specified string. Case insensitive.
/// </summary>
bool NameStartsWith(string matchString);
/// <summary>
/// Looks for a portrait by name on a character
/// If none is found, give a warning and return a blank sprite
/// </summary>
Sprite GetPortrait(string portraitString);
}
}

12
Assets/Fungus/Narrative/Scripts/ICharacter.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 07a9457a850c147049f1fb7ea4b860cf
timeCreated: 1473676955
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save