From 2f2fd5128f0727542402f2b99935a21389dad3de Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 12 Sep 2016 12:29:36 +0100 Subject: [PATCH] Refactored Character to use ICharacter interface --- Assets/Fungus/Narrative/Scripts/Character.cs | 72 +++++++++++-------- Assets/Fungus/Narrative/Scripts/ICharacter.cs | 66 +++++++++++++++++ .../Narrative/Scripts/ICharacter.cs.meta | 12 ++++ 3 files changed, 122 insertions(+), 28 deletions(-) create mode 100644 Assets/Fungus/Narrative/Scripts/ICharacter.cs create mode 100644 Assets/Fungus/Narrative/Scripts/ICharacter.cs.meta diff --git a/Assets/Fungus/Narrative/Scripts/Character.cs b/Assets/Fungus/Narrative/Scripts/Character.cs index 37257af8..21dd72b9 100644 --- a/Assets/Fungus/Narrative/Scripts/Character.cs +++ b/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. /// [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") - public virtual string NameText { get { return nameText; } } + [Tooltip("Color to display the character name in Say Dialog.")] [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; - 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 portraits; - public virtual List Portraits { get { return portraits; } } + [Tooltip("Direction that portrait sprites face.")] [SerializeField] protected FacingDirection portraitsFace; - public virtual FacingDirection PortraitsFace { get { return portraitsFace; } } - [SerializeField] protected PortraitState state = new PortraitState(); - 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.")] + [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.")] [SerializeField] protected SayDialog setSayDialog; - public virtual ISayDialog SetSayDialog { get { return setSayDialog; } } [FormerlySerializedAs("notes")] [TextArea(5,10)] [SerializeField] protected string description; + protected PortraitState portaitState = new PortraitState(); + static public List activeCharacters = new List(); protected virtual void OnEnable() @@ -58,18 +53,27 @@ namespace Fungus activeCharacters.Remove(this); } - #region ILocalizable implementation + #region ICharacter implementation - public virtual string GetStandardText() - { - return nameText; - } + public virtual string NameText { get { return nameText; } } - public virtual void SetStandardText(string standardText) - { - nameText = standardText; - } + public virtual Color NameColor { get { return nameColor; } } + + public virtual AudioClip SoundEffect { get { return soundEffect; } } + + public virtual Sprite ProfileSprite { get; set; } + public virtual List 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; } } + + /// + /// Returns true if the character name starts with the specified string. Case insensitive. + /// public bool NameStartsWith(string matchString) { return name.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture) @@ -80,18 +84,16 @@ namespace Fungus /// Looks for a portrait by name on a character /// If none is found, give a warning and return a blank sprite /// - /// - /// Character portrait sprite - public virtual Sprite GetPortrait(string portrait_string) + public virtual Sprite GetPortrait(string portraitString) { - if (String.IsNullOrEmpty(portrait_string)) + if (String.IsNullOrEmpty(portraitString)) { return null; } 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]; } @@ -99,6 +101,20 @@ namespace Fungus return null; } + #endregion + + #region ILocalizable implementation + + public virtual string GetStandardText() + { + return nameText; + } + + public virtual void SetStandardText(string standardText) + { + nameText = standardText; + } + public virtual string GetDescription() { return description; diff --git a/Assets/Fungus/Narrative/Scripts/ICharacter.cs b/Assets/Fungus/Narrative/Scripts/ICharacter.cs new file mode 100644 index 00000000..3039e231 --- /dev/null +++ b/Assets/Fungus/Narrative/Scripts/ICharacter.cs @@ -0,0 +1,66 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus +{ + /// + /// A Character that can be used in dialogue via the Say, Conversation and Portrait commands. + /// + public interface ICharacter + { + /// + /// Character name as displayed in Say Dialog. + /// + string NameText { get; } + + /// + /// Color to display the character name in Say Dialog. + /// + Color NameColor { get; } + + /// + /// Sound effect to play when this character is speaking. + /// + /// The sound effect. + AudioClip SoundEffect { get; } + + /// + /// List of portrait images that can be displayed for this character. + /// + List Portraits { get; } + + /// + /// Direction that portrait sprites face. + /// + FacingDirection PortraitsFace { get; } + + /// + /// Currently display profile sprite for this character. + /// + /// The profile sprite. + Sprite ProfileSprite { get; set; } + + /// + /// Current display state of this character's portrait. + /// + /// The state. + PortraitState State { get; } + + /// + /// 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. + /// + ISayDialog SetSayDialog { get; } + + /// + /// Returns true if the character name starts with the specified string. Case insensitive. + /// + bool NameStartsWith(string matchString); + + /// + /// Looks for a portrait by name on a character + /// If none is found, give a warning and return a blank sprite + /// + Sprite GetPortrait(string portraitString); + } +} \ No newline at end of file diff --git a/Assets/Fungus/Narrative/Scripts/ICharacter.cs.meta b/Assets/Fungus/Narrative/Scripts/ICharacter.cs.meta new file mode 100644 index 00000000..5fdff1de --- /dev/null +++ b/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: