Browse Source

Listen for activeSceneChanged for deactivation

Also for resetting near clip plane
habeebweeb 4 years ago
parent
commit
26f2c3163d
1 changed files with 14 additions and 9 deletions
  1. 14 9
      COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

+ 14 - 9
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.IO;
 using System.Collections;
 using System.Collections.Generic;
@@ -44,13 +44,25 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             ScreenshotEvent += OnScreenshotEvent;
             DontDestroyOnLoad(this);
+            UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
+            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnSceneChanged;
         }
 
         private void Start()
         {
             Constants.Initialize();
             Translation.Initialize(Translation.CurrentLanguage);
-            UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
+        }
+
+        private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
+        {
+            currentScene = (Constants.Scene)scene.buildIndex;
+        }
+
+        private void OnSceneChanged(Scene current, Scene next)
+        {
+            if (active) Deactivate(true);
+            ResetCalcNearClip();
         }
 
         public byte[] SerializeScene(bool kankyo = false)
@@ -333,13 +345,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
-        private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
-        {
-            currentScene = (Constants.Scene)scene.buildIndex;
-            if (active) Deactivate(true);
-            ResetCalcNearClip();
-        }
-
         private void Initialize()
         {
             if (initialized) return;