diff --git a/Source/Game/Console/ConsolePlugin.cs b/Source/Game/Console/ConsolePlugin.cs
index 5b11957..3aec316 100644
--- a/Source/Game/Console/ConsolePlugin.cs
+++ b/Source/Game/Console/ConsolePlugin.cs
@@ -7,7 +7,7 @@ using FlaxEditor;
namespace Game
{
- public class ConsolePlugin : GamePlugin
+ public class ConsolePlugin : GGamePlugin
{
public static PluginDescription DescriptionInternal = new PluginDescription
{
@@ -19,34 +19,31 @@ namespace Game
Category = "Game"
};
- public override void Initialize()
+ public override void Init()
{
- base.Initialize();
+ FlaxEngine.Debug.Log("ConsolePlugin initialized");
Console.Init();
}
- public override void Deinitialize()
+ public override void Deinit()
{
- base.Deinitialize();
}
}
#if FLAX_EDITOR
- public class ConsoleEditorPlugin : EditorPlugin
+ public class ConsoleEditorPlugin : GEditorPlugin
{
public override PluginDescription Description => ConsolePlugin.DescriptionInternal;
-
public override Type GamePluginType => typeof(ConsolePlugin);
- public override void Initialize()
+ public override void Init()
{
- base.Initialize();
+ FlaxEngine.Debug.Log("ConsolePlugin initialized");
Console.Init();
}
- public override void Deinitialize()
+ public override void Deinit()
{
- base.Deinitialize();
}
}
#endif
diff --git a/Source/Game/Network/NetworkManagerPlugin.cs b/Source/Game/Network/NetworkManagerPlugin.cs
index 36ad1c1..f18853c 100644
--- a/Source/Game/Network/NetworkManagerPlugin.cs
+++ b/Source/Game/Network/NetworkManagerPlugin.cs
@@ -8,8 +8,10 @@ using FlaxEditor;
namespace Game
{
- public class NetworkManagerPlugin : GamePlugin
+ public class NetworkManagerPlugin : GGamePlugin
{
+ public override Type[] PluginDependencies { get => new Type[] { typeof(ConsolePlugin) }; }
+
public static PluginDescription DescriptionInternal = new PluginDescription
{
Author = "Ari Vuollet",
@@ -20,37 +22,27 @@ namespace Game
Category = "Game"
};
- public override void Initialize()
+ public override void Init()
{
- base.Initialize();
- Console.Init();
+ FlaxEngine.Debug.Log("NetworkManagerPlugin initialized");
NetworkManager.Init();
}
-
- public override void Deinitialize()
- {
- base.Deinitialize();
- }
}
#if FLAX_EDITOR
- public class NetworkManagerEditorPlugin : EditorPlugin
+ public class NetworkManagerEditorPlugin : GEditorPlugin
{
- public override PluginDescription Description => NetworkManagerPlugin.DescriptionInternal;
+ public override Type[] PluginDependencies { get => new Type[] { typeof(ConsoleEditorPlugin) }; }
+ public override PluginDescription Description => NetworkManagerPlugin.DescriptionInternal;
public override Type GamePluginType => typeof(NetworkManagerPlugin);
- public override void Initialize()
+ public override void Init()
{
- base.Initialize();
- Console.Init();
+ FlaxEngine.Debug.Log("NetworkManagerPlugin initialized");
+ //Console.Init();
//NetworkManager.Init();
}
-
- public override void Deinitialize()
- {
- base.Deinitialize();
- }
}
#endif
}
\ No newline at end of file
diff --git a/Source/Game/Utility/GGamePlugin.cs b/Source/Game/Utility/GGamePlugin.cs
new file mode 100644
index 0000000..f79ef38
--- /dev/null
+++ b/Source/Game/Utility/GGamePlugin.cs
@@ -0,0 +1,164 @@
+using System;
+using System.Linq;
+using FlaxEngine;
+using Debug = System.Diagnostics.Debug;
+#if FLAX_EDITOR
+using FlaxEditor;
+#endif
+
+namespace Game
+{
+ ///
+ /// Wrapper for GamePlugin with support of initializing plugins in correct order.
+ /// The initialization is deferred to later time after the last dependant plugin is initialized.
+ ///
+ public abstract class GGamePlugin : GamePlugin
+ {
+ public virtual Type[] PluginDependencies { get => Array.Empty(); }
+ public bool Initialized { get; private set; }
+ public bool Deinitialized { get; private set; }
+
+ public override void Initialize()
+ {
+ //FlaxEngine.Debug.Log($"Plugin {this.GetType()}::Initialize");
+ base.Initialize();
+ if (!Initialized)
+ {
+ // Check if dependencies have been initialized, defer to later if not
+ bool dependenciesInitialized = true;
+ var plugins = PluginManager.GamePlugins.OfType().Where(x => x.GetType() != this.GetType());
+ foreach (var pluginType in PluginDependencies)
+ {
+ //FlaxEngine.Debug.Log($"Plugintype {pluginType}");
+ var plugin = plugins.FirstOrDefault(x => x.GetType() == pluginType);
+ if (plugin != null)
+ {
+ //FlaxEngine.Debug.Log($"Plugin {plugin.GetType()} is Initialized?");
+ if (!plugin.Initialized)
+ {
+ dependenciesInitialized = false;
+ break;
+ }
+ }
+ else
+ {
+ dependenciesInitialized = false;
+ break;
+ }
+ }
+
+ if (dependenciesInitialized)
+ {
+ Init();
+ Initialized = true;
+
+ // Initialize any previously deferred plugins in case their dependencies were initialized
+ foreach (var p in plugins)
+ {
+ //FlaxEngine.Debug.Log($"try init Plugin {p.GetType()}");
+ if (!p.Initialized /* && p.PluginDependencies.Contains(this.GetType())*/)
+ {
+ //FlaxEngine.Debug.Log($"Plugin run init {p.GetType()}");
+ p.Initialize();
+ }
+ }
+ }
+ }
+ }
+
+ public override void Deinitialize()
+ {
+ base.Deinitialize();
+ if (!Deinitialized)
+ {
+ Deinit();
+ Deinitialized = true;
+ }
+ }
+
+ public virtual void Init()
+ {
+ }
+ public virtual void Deinit()
+ {
+ }
+ }
+
+#if FLAX_EDITOR
+ ///
+ /// Wrapper for EditorPlugin with support of initializing plugins in correct order.
+ /// The initialization is deferred to later time after the last dependant plugin is initialized.
+ ///
+ public abstract class GEditorPlugin : EditorPlugin
+ {
+ public virtual Type[] PluginDependencies { get => Array.Empty(); }
+ public bool Initialized { get; private set; }
+ public bool Deinitialized { get; private set; }
+
+ public override void Initialize()
+ {
+ //FlaxEngine.Debug.Log($"Plugin {this.GetType()}::Initialize");
+ base.Initialize();
+ if (!Initialized)
+ {
+ // Check if dependencies have been initialized, defer to later if not
+ bool dependenciesInitialized = true;
+ var plugins = PluginManager.EditorPlugins.OfType().Where(x => x.GetType() != this.GetType());
+ foreach (var pluginType in PluginDependencies)
+ {
+ //FlaxEngine.Debug.Log($"Plugintype {pluginType}");
+ var plugin = plugins.FirstOrDefault(x => x.GetType() == pluginType);
+ if (plugin != null)
+ {
+ //FlaxEngine.Debug.Log($"Plugin {plugin.GetType()} is Initialized?");
+ if (!plugin.Initialized)
+ {
+ dependenciesInitialized = false;
+ break;
+ }
+ }
+ else
+ {
+ dependenciesInitialized = false;
+ break;
+ }
+ }
+
+ if (dependenciesInitialized)
+ {
+ Init();
+ Initialized = true;
+
+ // Initialize any previously deferred plugins in case their dependencies were initialized
+ foreach (var p in plugins)
+ {
+ //FlaxEngine.Debug.Log($"try init Plugin {p.GetType()}");
+ if (!p.Initialized /* && p.PluginDependencies.Contains(this.GetType())*/)
+ {
+ //FlaxEngine.Debug.Log($"Plugin run init {p.GetType()}");
+ p.Initialize();
+ }
+ }
+ }
+ }
+ }
+
+ public override void Deinitialize()
+ {
+ base.Deinitialize();
+ if (!Deinitialized)
+ {
+ Deinit();
+ Deinitialized = true;
+ }
+ }
+
+ public virtual void Init()
+ {
+ }
+ public virtual void Deinit()
+ {
+ }
+ }
+#endif
+}
\ No newline at end of file