Fixed script play mode info

This commit is contained in:
Simon Lübeß
2024-01-18 21:41:18 +01:00
parent c906fc9667
commit 04a0cecf3c
+26 -8
View File
@@ -893,11 +893,9 @@ namespace GlitchyEditor
using (Scene runtimeScene = new Scene()) using (Scene runtimeScene = new Scene())
{ {
ScriptEngine.ApplicationInfo.IsInPlayMode = true;
_editorScene.CopyTo(runtimeScene, true); _editorScene.CopyTo(runtimeScene, true);
SetActiveScene(runtimeScene, startRuntime: true, startSimulation: true); SetActiveScene(runtimeScene, startRuntime: true, startSimulation: true, newPlayMode: .Play);
ScriptEngine.DeserializeScriptInstances(_prePlaySerializedData); ScriptEngine.DeserializeScriptInstances(_prePlaySerializedData);
} }
@@ -908,15 +906,37 @@ namespace GlitchyEditor
SwitchToPlayWindow(); SwitchToPlayWindow();
} }
enum PlayMode
{
Play,
Editor,
Simulation
}
/// Activates the given scene. /// Activates the given scene.
/// @param scene The scene to be activated. /// @param scene The scene to be activated.
/// @param startRuntime If set to true, the script runtime will be initialized for the given scene. /// @param startRuntime If set to true, the script runtime will be initialized for the given scene.
/// @param startSimulation If set to true, the physics simulation will be initialized for the given scene. /// @param startSimulation If set to true, the physics simulation will be initialized for the given scene.
private void SetActiveScene(Scene scene, bool startRuntime, bool startSimulation) private void SetActiveScene(Scene scene, bool startRuntime, bool startSimulation, PlayMode? newPlayMode = null)
{ {
_activeScene?.StopRuntime(); _activeScene?.StopRuntime();
_activeScene?.StopSimulation(); _activeScene?.StopSimulation();
if (newPlayMode != null)
{
switch (newPlayMode.Value)
{
case .Play:
ScriptEngine.ApplicationInfo.IsInPlayMode = true;
case .Editor:
ScriptEngine.ApplicationInfo.IsInEditMode = true;
case .Simulation:
// No scripts in Simulation
ScriptEngine.ApplicationInfo.IsInEditMode = false;
ScriptEngine.ApplicationInfo.IsInPlayMode = false;
}
}
if (scene != null) if (scene != null)
{ {
if (startRuntime) if (startRuntime)
@@ -939,7 +959,7 @@ namespace GlitchyEditor
{ {
_editorScene.CopyTo(simulationScene, false); _editorScene.CopyTo(simulationScene, false);
SetActiveScene(simulationScene, startRuntime: false, startSimulation: true); SetActiveScene(simulationScene, startRuntime: false, startSimulation: true, newPlayMode: .Simulation);
} }
_editor.CurrentScene = _activeScene; _editor.CurrentScene = _activeScene;
@@ -975,9 +995,7 @@ namespace GlitchyEditor
/// Stops the simulation or game and returns to edit mode. /// Stops the simulation or game and returns to edit mode.
private void OnSceneStop() private void OnSceneStop()
{ {
ScriptEngine.ApplicationInfo.IsInEditMode = true; SetActiveScene(_editorScene, startRuntime: true, startSimulation: false, newPlayMode: .Editor);
SetActiveScene(_editorScene, startRuntime: true, startSimulation: false);
// TODO: _editorScene.DeserializeScripts(scriptData); // TODO: _editorScene.DeserializeScripts(scriptData);