diff --git a/Assets/Fungus/Scripts/Components/Character.cs b/Assets/Fungus/Scripts/Components/Character.cs index 21dd72b9..8c3634ee 100644 --- a/Assets/Fungus/Scripts/Components/Character.cs +++ b/Assets/Fungus/Scripts/Components/Character.cs @@ -71,19 +71,14 @@ namespace Fungus 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) + public string GetObjectName() { return gameObject.name; } + + public virtual bool NameStartsWith(string matchString) { return name.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture) || nameText.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture); } - /// - /// Looks for a portrait by name on a character - /// If none is found, give a warning and return a blank sprite - /// public virtual Sprite GetPortrait(string portraitString) { if (String.IsNullOrEmpty(portraitString)) diff --git a/Assets/Fungus/Scripts/Components/SayDialog.cs b/Assets/Fungus/Scripts/Components/SayDialog.cs index 3a6775a8..a7d400e6 100644 --- a/Assets/Fungus/Scripts/Components/SayDialog.cs +++ b/Assets/Fungus/Scripts/Components/SayDialog.cs @@ -17,7 +17,7 @@ namespace Fungus public static ISayDialog activeSayDialog; // Most recent speaking character - public static Character speakingCharacter; + public static ICharacter speakingCharacter; [Tooltip("Duration to fade dialogue in/out")] [SerializeField] protected float fadeDuration = 0.25f; @@ -245,7 +245,7 @@ namespace Fungus gameObject.SetActive(state); } - public virtual void SetCharacter(Character character, IFlowchart flowchart = null) + public virtual void SetCharacter(ICharacter character, IFlowchart flowchart = null) { if (character == null) { @@ -261,7 +261,7 @@ namespace Fungus } else { - Character prevSpeakingCharacter = speakingCharacter; + ICharacter prevSpeakingCharacter = speakingCharacter; speakingCharacter = character; // Dim portraits of non-speaking characters @@ -270,11 +270,11 @@ namespace Fungus if (stage.DimPortraits) { - foreach (Character c in stage.CharactersOnStage) + foreach (var c in stage.CharactersOnStage) { if (prevSpeakingCharacter != speakingCharacter) { - if (c != speakingCharacter) + if (c != null && !c.Equals(speakingCharacter)) { stage.SetDimmed(c, true); } @@ -292,7 +292,7 @@ namespace Fungus if (characterName == "") { // Use game object name as default - characterName = character.name; + characterName = character.GetObjectName(); } if (flowchart != null) diff --git a/Assets/Fungus/Scripts/Interfaces/ICharacter.cs b/Assets/Fungus/Scripts/Interfaces/ICharacter.cs index 3039e231..e721e215 100644 --- a/Assets/Fungus/Scripts/Interfaces/ICharacter.cs +++ b/Assets/Fungus/Scripts/Interfaces/ICharacter.cs @@ -52,6 +52,11 @@ namespace Fungus /// ISayDialog SetSayDialog { get; } + /// + /// Returns the name of the game object. + /// + string GetObjectName(); + /// /// Returns true if the character name starts with the specified string. Case insensitive. /// diff --git a/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs b/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs index 51ac8808..c37aecb7 100644 --- a/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs +++ b/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs @@ -18,7 +18,7 @@ namespace Fungus /// /// The active speaking character. /// An optional Flowchart to use for variable substitution in the character name string. - void SetCharacter(Character character, IFlowchart flowchart = null); + void SetCharacter(ICharacter character, IFlowchart flowchart = null); /// /// Sets the character image to display on the Say Dialog.