BoltEngine / Bolt-Tracker

New issue tracker for Photon Bolt
10 stars 2 forks source link

If you close Bolt Debug Start window it does not restore you to the scene you were editing #182

Open GetLitGames opened 3 years ago

GetLitGames commented 3 years ago

How to reproduce issue

BoltDebugStart window options - EditorMode: Server Clients:1 BuildOptions: Development Build

  1. Open Bolt Debug Start
  2. push SinglePlayer/Run as Server on a scene that is not the current scene in editor
  3. close Bolt Debug Start Window
  4. stop play

BoltDebugStart scene will be in the editor instead of your last scene.

if Bolt Debug Start window is left open, it does correctly restore you to the last scene but if it's closed it will not.

To fix this you can use code similar to below in a static class. Probably you already have some similar code that restores the scene but is not static and not InitializeOnLoad.

` [InitializeOnLoad] static class BoltDebugStartWindowRestoreScene { // Static constructor binds a playmode-changed callback. // [InitializeOnLoad] above makes sure this gets executed. static BoltDebugStartWindowRestoreScene() { EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; }

    // Play mode change callback handles the scene load/reload.
static void EditorApplication_playModeStateChanged(PlayModeStateChange obj)
{
    switch(obj)
    {
        case PlayModeStateChange.ExitingEditMode:
            SaveCurrentSceneName();
            break;
        case PlayModeStateChange.EnteredEditMode:
            LoadPreviousScene();
            break;
    }
}

   static void SaveCurrentSceneName() {
    lastSceneSetting = EditorSceneManager.GetActiveScene().path;
   }
   static void LoadPreviousScene() {
      EditorSceneManager.OpenScene(lastSceneSetting);
   }

`

Expected Behavior

Bolt Debug Start window should restore you to the correct editor scene you were in before you used it

Actual behavior

BoltDebugStart scene is shown in the editor instead of the scene you were working in before hitting Run as Server/Singleplayer using Bolt Debug Start window

Configuration