Browse Source

Fix issue with extra light being added to scene

Noticeable when loading a scene and finding out that the scene is way
too bright as a result of an extra light being added

An additional light is added to the scene on startup but does not show
up in the light dropdown. Saving the scene will save that light as well
and result in an extra light when loading that scene.

This also fixes another bug where quick saving (ctrl + S) right when MM
starts up and then quick loading (ctrl + A) complelely breaks MM when
switching to the BG tab
habeebweeb 4 years ago
parent
commit
d0f41aecdd

+ 34 - 25
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.MaidUpdate.cs

@@ -688,31 +688,40 @@ namespace CM3D2.MultipleMaids.Plugin
                     subcamera.cullingMask = 256;
                     subcamera.depth = 1f;
                     subcamera.transform.parent = mainCamera.transform;
-                    float num2 = 2f;
-                    if (Application.unityVersion.StartsWith("4"))
-                    {
-                        num2 = 1f;
-                    }
-
-                    GameObject gameObject3 = new GameObject("Light");
-                    gameObject3.AddComponent<Light>();
-                    lightList.Add(gameObject3);
-                    lightColorR.Add(1f);
-                    lightColorG.Add(1f);
-                    lightColorB.Add(1f);
-                    lightIndex.Add(0);
-                    lightX.Add(40f);
-                    lightY.Add(180f);
-                    lightAkarusa.Add(num2);
-                    lightKage.Add(0.098f);
-                    lightRange.Add(50f);
-                    gameObject3.transform.position = GameMain.Instance.MainLight.transform.position;
-                    gameObject3.GetComponent<Light>().intensity = num2;
-                    gameObject3.GetComponent<Light>().spotAngle = 50f;
-                    gameObject3.GetComponent<Light>().range = 10f;
-                    gameObject3.GetComponent<Light>().type = LightType.Directional;
-                    gameObject3.GetComponent<Light>().color = new Color(0.5f, 1f, 0f);
-                    gameObject3.GetComponent<Light>().cullingMask = 256;
+
+                    if (lightList.Count == 0)
+                    {
+                        float num2 = 2f;
+                        if (Application.unityVersion.StartsWith("4"))
+                        {
+                            num2 = 1f;
+                        }
+
+                        GameObject gameObject3 = new GameObject("Light");
+                        gameObject3.AddComponent<Light>();
+                        lightList.Add(gameObject3);
+                        lightColorR.Add(1f);
+                        lightColorG.Add(1f);
+                        lightColorB.Add(1f);
+                        lightIndex.Add(0);
+                        lightX.Add(40f);
+                        lightY.Add(180f);
+                        lightAkarusa.Add(num2);
+                        lightKage.Add(0.098f);
+                        lightRange.Add(50f);
+                        gameObject3.transform.position = GameMain.Instance.MainLight.transform.position;
+                        gameObject3.GetComponent<Light>().intensity = num2;
+                        gameObject3.GetComponent<Light>().spotAngle = 50f;
+                        gameObject3.GetComponent<Light>().range = 10f;
+                        gameObject3.GetComponent<Light>().type = LightType.Directional;
+                        gameObject3.GetComponent<Light>().color = new Color(0.5f, 1f, 0f);
+                        gameObject3.GetComponent<Light>().cullingMask = 256;
+
+                        // lightComboList = new GUIContent[lightList.Count];
+                        // lightComboList[0] = new GUIContent("メイン");
+                        // lightCombo.selectedItemIndex = 0;
+                        // selectLightIndex = 0;
+                    }
                 }
 
                 if (getModKeyPressing(modKey.Shift) && !getModKeyPressing(modKey.Ctrl) && !getModKeyPressing(modKey.Alt)

+ 34 - 25
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Update.cs

@@ -5881,31 +5881,40 @@ namespace CM3D2.MultipleMaids.Plugin
                     subcamera.cullingMask = 256;
                     subcamera.depth = 1f;
                     subcamera.transform.parent = mainCamera.transform;
-                    float num = 2f;
-                    if (Application.unityVersion.StartsWith("4"))
-                    {
-                        num = 1f;
-                    }
-
-                    GameObject gameObject = new GameObject("Light");
-                    gameObject.AddComponent<Light>();
-                    lightList.Add(gameObject);
-                    lightColorR.Add(1f);
-                    lightColorG.Add(1f);
-                    lightColorB.Add(1f);
-                    lightIndex.Add(0);
-                    lightX.Add(40f);
-                    lightY.Add(180f);
-                    lightAkarusa.Add(num);
-                    lightKage.Add(0.098f);
-                    lightRange.Add(50f);
-                    gameObject.transform.position = GameMain.Instance.MainLight.transform.position;
-                    gameObject.GetComponent<Light>().intensity = 2f;
-                    gameObject.GetComponent<Light>().spotAngle = 50f;
-                    gameObject.GetComponent<Light>().range = 10f;
-                    gameObject.GetComponent<Light>().type = LightType.Directional;
-                    gameObject.GetComponent<Light>().color = new Color(0.5f, 1f, 0.0f);
-                    gameObject.GetComponent<Light>().cullingMask = 256;
+
+                    if (lightList.Count == 0)
+                    {
+                        float num = 2f;
+                        if (Application.unityVersion.StartsWith("4"))
+                        {
+                            num = 1f;
+                        }
+
+                        GameObject gameObject = new GameObject("Light");
+                        gameObject.AddComponent<Light>();
+                        lightList.Add(gameObject);
+                        lightColorR.Add(1f);
+                        lightColorG.Add(1f);
+                        lightColorB.Add(1f);
+                        lightIndex.Add(0);
+                        lightX.Add(40f);
+                        lightY.Add(180f);
+                        lightAkarusa.Add(num);
+                        lightKage.Add(0.098f);
+                        lightRange.Add(50f);
+                        gameObject.transform.position = GameMain.Instance.MainLight.transform.position;
+                        gameObject.GetComponent<Light>().intensity = 2f;
+                        gameObject.GetComponent<Light>().spotAngle = 50f;
+                        gameObject.GetComponent<Light>().range = 10f;
+                        gameObject.GetComponent<Light>().type = LightType.Directional;
+                        gameObject.GetComponent<Light>().color = new Color(0.5f, 1f, 0.0f);
+                        gameObject.GetComponent<Light>().cullingMask = 256;
+
+                        // lightComboList = new GUIContent[lightList.Count];
+                        // lightComboList[0] = new GUIContent("メイン");
+                        // lightCombo.selectedItemIndex = 0;
+                        // selectLightIndex = 0;
+                    }
                 }
 
                 if ((!isF6S || !getModKeyPressing(modKey.Shift) || !Input.GetKeyDown(KeyCode.F6))