141 lines
3.8 KiB
C#
141 lines
3.8 KiB
C#
using System;
|
|
using FlaxEngine;
|
|
using Console = Game.Console;
|
|
using System.Linq;
|
|
#if FLAX_EDITOR
|
|
using FlaxEditor;
|
|
#endif
|
|
|
|
namespace Game
|
|
{
|
|
public class ConsolePlugin : GamePlugin
|
|
{
|
|
public ConsolePlugin()
|
|
{
|
|
#if FLAX_EDITOR
|
|
_description = ConsoleEditorPlugin.DescriptionInternal;
|
|
#endif
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
//FlaxEngine.Debug.Log("ConsolePlugin initialized");
|
|
Console.Init();
|
|
|
|
//AssetManager.Init(); // TODO: move these elsewhere
|
|
#if !FLAX_EDITOR
|
|
Level.SceneLoaded += OnSceneLoaded;
|
|
#endif
|
|
}
|
|
|
|
public override void Deinitialize()
|
|
{
|
|
#if !FLAX_EDITOR
|
|
Level.SceneLoaded -= OnSceneLoaded;
|
|
#endif
|
|
}
|
|
|
|
private void OnSceneLoaded(Scene scene, Guid guid)
|
|
{
|
|
Level.SceneLoaded -= OnSceneLoaded;
|
|
LoadConfig();
|
|
}
|
|
|
|
private void LoadConfig()
|
|
{
|
|
Console.Print("Loading config file (GamePlugin)");
|
|
AssetManager.Globals.ResetValues();
|
|
|
|
foreach (var line in AssetManager.Config.GetLines())
|
|
Console.Execute(line, false, true);
|
|
}
|
|
}
|
|
|
|
#if FLAX_EDITOR
|
|
public class ConsoleEditorPlugin : EditorPlugin
|
|
{
|
|
public static PluginDescription DescriptionInternal = new PluginDescription
|
|
{
|
|
Author = "Ari Vuollet",
|
|
Name = "Console",
|
|
Description = "Quake-like console",
|
|
Version = Version.Parse("0.1.0"),
|
|
IsAlpha = true,
|
|
Category = "Game"
|
|
};
|
|
|
|
public override Type GamePluginType => typeof(ConsolePlugin);
|
|
|
|
public ConsoleEditorPlugin()
|
|
{
|
|
_description = DescriptionInternal;
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
//FlaxEngine.Debug.Log("ConsolePlugin initialized");
|
|
Console.Init();
|
|
|
|
//AssetManager.Init();
|
|
|
|
Level.SceneLoaded += OnSceneLoaded;
|
|
|
|
FlaxEditor.Editor.Instance.PlayModeBegin += OnPlayModeBegin;
|
|
FlaxEditor.Editor.Instance.PlayModeEnd += OnPlayModeEnd;
|
|
//Scripting.Exit += OnScriptingExit;
|
|
|
|
/*AssetManager.Init(); // TODO: move these elsewhere
|
|
AssetManager.Globals.ResetValues();
|
|
|
|
foreach (var line in AssetManager.Config.GetLines())
|
|
Console.Execute(line, false, true);*/
|
|
}
|
|
|
|
/*private void OnScriptingExit()
|
|
{
|
|
FlaxEditor.Editor.Instance.PlayModeBegin -= OnPlayModeBegin;
|
|
FlaxEditor.Editor.Instance.PlayModeEnd -= OnPlayModeEnd;
|
|
}*/
|
|
|
|
private void OnPlayModeBegin()
|
|
{
|
|
//FlaxEditor.Editor.Instance.PlayModeBegin -= Instance_PlayModeBegin;
|
|
LoadConfig();
|
|
GameMode.StartServer(true);
|
|
}
|
|
|
|
private void OnPlayModeEnd()
|
|
{
|
|
GameMode.StopServer();
|
|
}
|
|
|
|
public override void Deinitialize()
|
|
{
|
|
Level.SceneLoaded -= OnSceneLoaded;
|
|
Level.SceneLoaded -= OnSceneLoaded;
|
|
if (FlaxEditor.Editor.Instance != null)
|
|
{
|
|
FlaxEditor.Editor.Instance.PlayModeBegin -= OnPlayModeBegin;
|
|
FlaxEditor.Editor.Instance.PlayModeEnd -= OnPlayModeEnd;
|
|
}
|
|
}
|
|
|
|
private void OnSceneLoaded(Scene scene, Guid guid)
|
|
{
|
|
Level.SceneLoaded -= OnSceneLoaded;
|
|
Level.SceneLoaded -= OnSceneLoaded;
|
|
LoadConfig();
|
|
}
|
|
|
|
private void LoadConfig()
|
|
{
|
|
Console.Print("Loading config file (EditorPlugin)");
|
|
|
|
AssetManager.Globals.ResetValues();
|
|
|
|
foreach (var line in AssetManager.Config.GetLines())
|
|
Console.Execute(line, false, true);
|
|
}
|
|
}
|
|
#endif
|
|
} |