From 366b58233e4a1a93e613b736216553c85d266851 Mon Sep 17 00:00:00 2001 From: artman41 Date: Tue, 15 May 2018 15:59:17 +0100 Subject: [PATCH] - Added old methods as support for old plugins --- IllusionInjector/CompositePlugin.cs | 32 +++++++++++++++++++++++++++++ IllusionInjector/PluginComponent.cs | 17 +++++++++++++++ IllusionPlugin/IPlugin.cs | 5 +++++ 3 files changed, 54 insertions(+) diff --git a/IllusionInjector/CompositePlugin.cs b/IllusionInjector/CompositePlugin.cs index f43d9c7f..a2a30568 100644 --- a/IllusionInjector/CompositePlugin.cs +++ b/IllusionInjector/CompositePlugin.cs @@ -80,6 +80,38 @@ namespace IllusionInjector { Invoke(plugin => plugin.OnFixedUpdate()); } + [Obsolete("Use OnSceneLoaded instead")] + public void OnLevelWasLoaded(int level) + { + foreach (var plugin in plugins) + { + try + { + plugin.OnLevelWasLoaded(level); + } + catch (Exception ex) + { + Console.WriteLine("{0}: {1}", plugin.Name, ex); + } + } + } + + [Obsolete("Use OnSceneLoaded instead")] + public void OnLevelWasInitialized(int level) + { + foreach (var plugin in plugins) + { + try + { + plugin.OnLevelWasInitialized(level); + } + catch (Exception ex) + { + Console.WriteLine("{0}: {1}", plugin.Name, ex); + } + } + } + public string Name { get { throw new NotImplementedException(); } diff --git a/IllusionInjector/PluginComponent.cs b/IllusionInjector/PluginComponent.cs index 63602464..f9b47e40 100644 --- a/IllusionInjector/PluginComponent.cs +++ b/IllusionInjector/PluginComponent.cs @@ -9,6 +9,7 @@ namespace IllusionInjector public class PluginComponent : MonoBehaviour { private CompositePlugin plugins; + private bool freshlyLoaded = false; private bool quitting = false; public static PluginComponent Create() @@ -27,9 +28,19 @@ namespace IllusionInjector SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneUnloaded += OnSceneUnloaded; } + + void Start() + { + OnLevelWasLoaded(Application.loadedLevel); + } void Update() { + if (freshlyLoaded) + { + freshlyLoaded = false; + plugins.OnLevelWasInitialized(Application.loadedLevel); + } plugins.OnUpdate(); } @@ -61,6 +72,12 @@ namespace IllusionInjector quitting = true; } + + void OnLevelWasLoaded(int level) + { + plugins.OnLevelWasLoaded(level); + freshlyLoaded = true; + } void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { diff --git a/IllusionPlugin/IPlugin.cs b/IllusionPlugin/IPlugin.cs index 7d3ffea8..34de5ef2 100644 --- a/IllusionPlugin/IPlugin.cs +++ b/IllusionPlugin/IPlugin.cs @@ -62,5 +62,10 @@ namespace IllusionPlugin /// Gets invoked on ever physics update. /// void OnFixedUpdate(); + + [Obsolete("Use OnSceneLoaded instead")] + void OnLevelWasLoaded(int level); + [Obsolete("Use OnSceneLoaded instead")] + void OnLevelWasInitialized(int level); } }