Browse Source

Add setting near clip plane

Near clip plane only gets updated when there are maids loaded in
CharacterMgr but given that maids past 16 are outside of the bounds, the
near clip lane does not get updated.
habeebweeb 4 years ago
parent
commit
38617c2e93
1 changed files with 24 additions and 2 deletions
  1. 24 2
      COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

+ 24 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

@@ -9,6 +9,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     [BepInPlugin(pluginGuid, pluginName, pluginVersion)]
     public class MeidoPhotoStudio : BaseUnityPlugin
     {
+        private static CameraMain mainCamera = GameMain.Instance.MainCamera;
         private const string pluginGuid = "com.habeebweeb.com3d2.meidophotostudio";
         public const string pluginName = "MeidoPhotoStudio";
         public const string pluginVersion = "0.0.0";
@@ -126,6 +127,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
         {
             currentScene = (Constants.Scene)scene.buildIndex;
+            ResetCalcNearClip();
         }
 
         private void Initialize()
@@ -162,8 +164,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private void Activate()
         {
             if (!initialized) Initialize();
+
+            SetNearClipPlane();
+
             uiActive = true;
-            isActive = true;
+            active = true;
 
             meidoManager.Activate();
             environmentManager.Activate();
@@ -181,8 +186,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (meidoManager.Busy) return;
 
+            ResetCalcNearClip();
+
             uiActive = false;
-            isActive = false;
+            active = false;
 
             meidoManager.Deactivate();
             environmentManager.Deactivate();
@@ -195,5 +202,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GameObject dailyPanel = GameObject.Find("UI Root")?.transform.Find("DailyPanel")?.gameObject;
             dailyPanel?.SetActive(true);
         }
+
+        private void SetNearClipPlane()
+        {
+            mainCamera.StopAllCoroutines();
+            mainCamera.m_bCalcNearClip = false;
+            mainCamera.camera.nearClipPlane = 0.01f;
+        }
+
+        private void ResetCalcNearClip()
+        {
+            if (mainCamera.m_bCalcNearClip) return;
+            mainCamera.StopAllCoroutines();
+            mainCamera.m_bCalcNearClip = true;
+            mainCamera.Start();
+        }
     }
 }