Browse Source

Fixed Fungus ignores existing “SayDialog” and creates another one #555

master
Christopher 8 years ago
parent
commit
e9aa381f20
  1. 27
      Assets/Fungus/Scripts/Components/SayDialog.cs

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

@ -5,6 +5,7 @@ using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus
{
@ -54,6 +55,22 @@ namespace Fungus
protected StringSubstituter stringSubstituter = new StringSubstituter();
// Cache active Say Dialogs to avoid expensive scene search
protected static List<SayDialog> activeSayDialogs = new List<SayDialog>();
protected void Awake()
{
if (!activeSayDialogs.Contains(this))
{
activeSayDialogs.Add(this);
}
}
protected void OnDestroy()
{
activeSayDialogs.Remove(this);
}
protected Writer GetWriter()
{
if (writer != null)
@ -200,8 +217,14 @@ namespace Fungus
{
if (ActiveSayDialog == null)
{
// Use first Say Dialog found in the scene (if any)
SayDialog sd = GameObject.FindObjectOfType<SayDialog>();
SayDialog sd = null;
// Use first active Say Dialog in the scene (if any)
if (activeSayDialogs.Count > 0)
{
sd = activeSayDialogs[0];
}
if (sd != null)
{
ActiveSayDialog = sd;

Loading…
Cancel
Save