Browse Source

Merge pull request #639 from stevehalliwell/SceneLoadedUnregisterBug

SceneManager Delegate handling moved
master
Steve Halliwell 7 years ago committed by GitHub
parent
commit
2fe61e7801
  1. 21
      Assets/Fungus/Scripts/Components/Flowchart.cs
  2. 17
      Assets/Fungus/Scripts/Components/Localization.cs

21
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -87,14 +87,6 @@ namespace Fungus
protected StringSubstituter stringSubstituer;
#if UNITY_5_4_OR_NEWER
protected virtual void Awake()
{
CheckEventSystem();
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (A, B) => {
LevelWasLoaded();
};
}
#else
protected virtual void OnLevelWasLoaded(int level)
{
@ -137,11 +129,20 @@ namespace Fungus
eventSystemPresent = true;
}
private void SceneManager_activeSceneChanged(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.Scene arg1)
{
LevelWasLoaded();
}
protected virtual void OnEnable()
{
if (!cachedFlowcharts.Contains(this))
{
cachedFlowcharts.Add(this);
//TODO these pairs could be replaced by something static that manages all active flowcharts
#if UNITY_5_4_OR_NEWER
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
#endif
}
CheckItemIds();
@ -155,6 +156,10 @@ namespace Fungus
{
cachedFlowcharts.Remove(this);
#if UNITY_5_4_OR_NEWER
UnityEngine.SceneManagement.SceneManager.activeSceneChanged -= SceneManager_activeSceneChanged;
#endif
StringSubstituter.UnregisterHandler(this);
}

17
Assets/Fungus/Scripts/Components/Localization.cs

@ -42,12 +42,6 @@ namespace Fungus
protected static Dictionary<string, string> localizedStrings = new Dictionary<string, string>();
#if UNITY_5_4_OR_NEWER
protected virtual void Awake()
{
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (A, B) => {
LevelWasLoaded();
};
}
#else
public virtual void OnLevelWasLoaded(int level)
{
@ -65,14 +59,25 @@ namespace Fungus
}
}
private void SceneManager_activeSceneChanged(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.Scene arg1)
{
LevelWasLoaded();
}
protected virtual void OnEnable()
{
StringSubstituter.RegisterHandler(this);
#if UNITY_5_4_OR_NEWER
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
#endif
}
protected virtual void OnDisable()
{
StringSubstituter.UnregisterHandler(this);
#if UNITY_5_4_OR_NEWER
UnityEngine.SceneManagement.SceneManager.activeSceneChanged -= SceneManager_activeSceneChanged;
#endif
}
protected virtual void Start()

Loading…
Cancel
Save