Browse Source

SayDialog.SetCharacter uses ICharacter interface

master
Christopher 8 years ago
parent
commit
34dc2db353
  1. 11
      Assets/Fungus/Scripts/Components/Character.cs
  2. 12
      Assets/Fungus/Scripts/Components/SayDialog.cs
  3. 5
      Assets/Fungus/Scripts/Interfaces/ICharacter.cs
  4. 2
      Assets/Fungus/Scripts/Interfaces/ISayDialog.cs

11
Assets/Fungus/Scripts/Components/Character.cs

@ -71,19 +71,14 @@ namespace Fungus
public virtual ISayDialog SetSayDialog { get { return setSayDialog; } } public virtual ISayDialog SetSayDialog { get { return setSayDialog; } }
/// <summary> public string GetObjectName() { return gameObject.name; }
/// Returns true if the character name starts with the specified string. Case insensitive.
/// </summary> public virtual 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)
|| nameText.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>
public virtual Sprite GetPortrait(string portraitString) public virtual Sprite GetPortrait(string portraitString)
{ {
if (String.IsNullOrEmpty(portraitString)) if (String.IsNullOrEmpty(portraitString))

12
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -17,7 +17,7 @@ namespace Fungus
public static ISayDialog activeSayDialog; public static ISayDialog activeSayDialog;
// Most recent speaking character // Most recent speaking character
public static Character speakingCharacter; public static ICharacter speakingCharacter;
[Tooltip("Duration to fade dialogue in/out")] [Tooltip("Duration to fade dialogue in/out")]
[SerializeField] protected float fadeDuration = 0.25f; [SerializeField] protected float fadeDuration = 0.25f;
@ -245,7 +245,7 @@ namespace Fungus
gameObject.SetActive(state); gameObject.SetActive(state);
} }
public virtual void SetCharacter(Character character, IFlowchart flowchart = null) public virtual void SetCharacter(ICharacter character, IFlowchart flowchart = null)
{ {
if (character == null) if (character == null)
{ {
@ -261,7 +261,7 @@ namespace Fungus
} }
else else
{ {
Character prevSpeakingCharacter = speakingCharacter; ICharacter prevSpeakingCharacter = speakingCharacter;
speakingCharacter = character; speakingCharacter = character;
// Dim portraits of non-speaking characters // Dim portraits of non-speaking characters
@ -270,11 +270,11 @@ namespace Fungus
if (stage.DimPortraits) if (stage.DimPortraits)
{ {
foreach (Character c in stage.CharactersOnStage) foreach (var c in stage.CharactersOnStage)
{ {
if (prevSpeakingCharacter != speakingCharacter) if (prevSpeakingCharacter != speakingCharacter)
{ {
if (c != speakingCharacter) if (c != null && !c.Equals(speakingCharacter))
{ {
stage.SetDimmed(c, true); stage.SetDimmed(c, true);
} }
@ -292,7 +292,7 @@ namespace Fungus
if (characterName == "") if (characterName == "")
{ {
// Use game object name as default // Use game object name as default
characterName = character.name; characterName = character.GetObjectName();
} }
if (flowchart != null) if (flowchart != null)

5
Assets/Fungus/Scripts/Interfaces/ICharacter.cs

@ -52,6 +52,11 @@ namespace Fungus
/// </summary> /// </summary>
ISayDialog SetSayDialog { get; } ISayDialog SetSayDialog { get; }
/// <summary>
/// Returns the name of the game object.
/// </summary>
string GetObjectName();
/// <summary> /// <summary>
/// Returns true if the character name starts with the specified string. Case insensitive. /// Returns true if the character name starts with the specified string. Case insensitive.
/// </summary> /// </summary>

2
Assets/Fungus/Scripts/Interfaces/ISayDialog.cs

@ -18,7 +18,7 @@ namespace Fungus
/// </summary> /// </summary>
/// <param name="character">The active speaking character.</param> /// <param name="character">The active speaking character.</param>
/// <param name="flowchart">An optional Flowchart to use for variable substitution in the character name string.</param> /// <param name="flowchart">An optional Flowchart to use for variable substitution in the character name string.</param>
void SetCharacter(Character character, IFlowchart flowchart = null); void SetCharacter(ICharacter character, IFlowchart flowchart = null);
/// <summary> /// <summary>
/// Sets the character image to display on the Say Dialog. /// Sets the character image to display on the Say Dialog.

Loading…
Cancel
Save