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; } }
/// <summary>
/// Returns true if the character name starts with the specified string. Case insensitive.
/// </summary>
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);
}
/// <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)
{
if (String.IsNullOrEmpty(portraitString))

12
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)

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

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

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

@ -18,7 +18,7 @@ namespace Fungus
/// </summary>
/// <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>
void SetCharacter(Character character, IFlowchart flowchart = null);
void SetCharacter(ICharacter character, IFlowchart flowchart = null);
/// <summary>
/// Sets the character image to display on the Say Dialog.

Loading…
Cancel
Save