Selaa lähdekoodia

Move managers out of EnvironmentManager

habeebweeb 4 vuotta sitten
vanhempi
commit
5969e8d08f

+ 19 - 12
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/DragPoint/DragPointLight.cs

@@ -5,6 +5,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal class DragPointLight : DragPointGeneral
     {
+        public static EnvironmentManager environmentManager { private get; set; }
         private Light light;
         public enum MPSLightType
         {
@@ -39,13 +40,15 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private bool isColourMode = false;
         public bool IsColourMode
         {
-            get => isColourMode && SelectedLightType == MPSLightType.Normal;
+            get => IsMain && isColourMode && SelectedLightType == MPSLightType.Normal;
             set
             {
+                if (!IsMain) return;
                 this.light.color = value ? Color.white : LightColour;
                 camera.backgroundColor = value ? LightColour : Color.black;
                 this.isColourMode = value;
                 LightColour = this.isColourMode ? camera.backgroundColor : light.color;
+                environmentManager.BGVisible = !IsColourMode;
             }
         }
         public Quaternion Rotation
@@ -141,7 +144,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.light.transform.position = LightProperty.DefaultPosition;
             this.light.transform.rotation = LightProperty.DefaultRotation;
 
-            SetLightType(LightType.Directional);
+            SetLightType(MPSLightType.Normal);
             this.ScaleFactor = 50f;
         }
 
@@ -192,28 +195,32 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
-        public void SetLightType(LightType type)
+        public void SetLightType(MPSLightType type)
         {
+            LightType lightType = LightType.Directional;
+
             string name = "normal";
+            SelectedLightType = type;
 
-            if (type == LightType.Directional)
-            {
-                SelectedLightType = MPSLightType.Normal;
-            }
-            else if (type == LightType.Spot)
+            if (type == MPSLightType.Spot)
             {
+                lightType = LightType.Spot;
                 name = "spot";
-                SelectedLightType = MPSLightType.Spot;
             }
-            else
+            else if (type == MPSLightType.Point)
             {
+                lightType = LightType.Point;
                 name = "point";
-                SelectedLightType = MPSLightType.Point;
             }
 
-            this.light.type = type;
+            this.light.type = lightType;
             this.Name = IsMain ? "main" : name;
 
+            if (IsMain)
+            {
+                environmentManager.BGVisible = !(IsColourMode && SelectedLightType == MPSLightType.Normal);
+            }
+
             SetProps();
             ApplyDragType();
         }

+ 3 - 26
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/LightsPane.cs

@@ -8,7 +8,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     internal class LightsPane : BasePane
     {
         private LightManager lightManager;
-        private EnvironmentManager environmentManager;
         private static readonly string[] lightTypes = { "normal", "spot", "point" };
         private Dictionary<LightProp, Slider> LightSlider;
         private Dropdown lightDropdown;
@@ -41,13 +40,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             { "backgroundWindow", "blue" }
         };
 
-        public LightsPane(EnvironmentManager environmentManager)
+        public LightsPane(LightManager lightManager)
         {
             this.lightHeader = Translation.Get("lightsPane", "header");
 
-            this.environmentManager = environmentManager;
-
-            this.lightManager = this.environmentManager.LightManager;
+            this.lightManager = lightManager;
             this.lightManager.Rotate += (s, a) => UpdateRotation();
             this.lightManager.Scale += (s, a) => UpdateScale();
             this.lightManager.Select += (s, a) => UpdateCurrentLight();
@@ -123,7 +120,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private void SetColourMode()
         {
             this.lightManager.SetColourModeActive(this.colorToggle.Value);
-            this.environmentManager.BGVisible = !this.colorToggle.Value;
             this.UpdatePane();
         }
 
@@ -172,28 +168,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             currentLightType = (MPSLightType)this.lightTypeGrid.SelectedItemIndex;
 
-            LightType lightType;
-            if (currentLightType == MPSLightType.Normal)
-            {
-                lightType = LightType.Directional;
-            }
-            else if (currentLightType == MPSLightType.Spot)
-            {
-                lightType = LightType.Spot;
-            }
-            else
-            {
-                lightType = LightType.Point;
-            }
-
             DragPointLight currentLight = lightManager.CurrentLight;
-            currentLight.SetLightType(lightType);
 
-            if (lightManager.SelectedLightIndex == 0)
-            {
-                this.environmentManager.BGVisible = (currentLight.SelectedLightType != DragPointLight.MPSLightType.Normal)
-                    || !currentLight.IsColourMode;
-            }
+            currentLight.SetLightType(currentLightType);
 
             this.lightDropdown.SetDropdownItem(lightManager.ActiveLightName);
             this.UpdatePane();

+ 1 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/BG2WindowPane.cs

@@ -2,7 +2,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal class BG2WindowPane : BaseWindowPane
     {
-        private EnvironmentManager environmentManager;
         private MeidoManager meidoManager;
         private PropsPane propsPane;
         private AttachPropPane attachPropPane;
@@ -11,12 +10,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private SelectionGrid propTabs;
         private BasePane currentPropsPane;
 
-        public BG2WindowPane(MeidoManager meidoManager, EnvironmentManager environmentManager)
+        public BG2WindowPane(MeidoManager meidoManager, PropManager propManager)
         {
-            this.environmentManager = environmentManager;
             this.meidoManager = meidoManager;
 
-            PropManager propManager = this.environmentManager.PropManager;
             this.propsPane = AddPane(new PropsPane(propManager));
             this.myRoomPropsPane = AddPane(new MyRoomPropsPane(propManager));
             this.modPropsPane = AddPane(new ModPropsPane(propManager));

+ 4 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/BGWindowPane.cs

@@ -9,13 +9,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private EffectsPane effectsPane;
         private DragPointPane dragPointPane;
 
-        public BGWindowPane(EnvironmentManager environmentManager)
+        public BGWindowPane(
+            EnvironmentManager environmentManager, LightManager lightManager, EffectManager effectManager
+        )
         {
             this.backgroundSelectorPane = AddPane(new BackgroundSelectorPane(environmentManager));
             this.dragPointPane = AddPane(new DragPointPane());
-            this.lightsPane = AddPane(new LightsPane(environmentManager));
-
-            EffectManager effectManager = environmentManager.EffectManager;
+            this.lightsPane = AddPane(new LightsPane(lightManager));
 
             this.effectsPane = AddPane(new EffectsPane()
             {

+ 7 - 17
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EnvironmentManager.cs

@@ -39,9 +39,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Transform bg;
         private CameraInfo cameraInfo;
         private DragPointBG bgDragPoint;
-        public LightManager LightManager { get; }
-        public PropManager PropManager { get; }
-        public EffectManager EffectManager { get; }
         private bool bgVisible = true;
         public bool BGVisible
         {
@@ -55,9 +52,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public EnvironmentManager(MeidoManager meidoManager)
         {
-            PropManager = new PropManager(meidoManager);
-            LightManager = new LightManager();
-            EffectManager = new EffectManager();
+            DragPointLight.environmentManager = this;
         }
 
         public void Activate()
@@ -87,17 +82,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             bgObject.SetActive(true);
             GameMain.Instance.BgMgr.ChangeBg("Theater");
 
-            UltimateOrbitCamera UOCamera =
+            UltimateOrbitCamera uoCamera =
                 Utility.GetFieldValue<CameraMain, UltimateOrbitCamera>(GameMain.Instance.MainCamera, "m_UOCamera");
-            UOCamera.enabled = true;
+            uoCamera.enabled = true;
 
             ResetCamera();
             SaveCameraInfo();
 
-            PropManager.Activate();
-            LightManager.Activate();
-            EffectManager.Activate();
-
             CubeSmallChange += OnCubeSmall;
             CubeActiveChange += OnCubeActive;
         }
@@ -108,9 +99,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GameObject.Destroy(cameraObject);
             GameObject.Destroy(subCamera);
 
-            PropManager.Deactivate();
-            LightManager.Deactivate();
-            EffectManager.Deactivate();
+            BGVisible = true;
+            Camera mainCamera = GameMain.Instance.MainCamera.camera;
+            mainCamera.backgroundColor = Color.black;
 
             bool isNight = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯") == 3;
 
@@ -127,6 +118,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0.5609447f, 1.380762f, -1.382336f), true);
             GameMain.Instance.MainCamera.SetDistance(1.6f, true);
             GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(245.5691f, 6.273283f), true);
+            bg.localScale = Vector3.one;
             CubeSmallChange -= OnCubeSmall;
             CubeActiveChange -= OnCubeActive;
         }
@@ -150,8 +142,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     ResetCamera();
                 }
             }
-
-            EffectManager.Update();
         }
 
         public void ChangeBackground(string assetName, bool creative = false)

+ 18 - 6
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

@@ -1,4 +1,4 @@
-using System.Collections;
+using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
@@ -17,6 +17,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private MeidoManager meidoManager;
         private EnvironmentManager environmentManager;
         private MessageWindowManager messageWindowManager;
+        private LightManager lightManager;
+        private PropManager propManager;
+        private EffectManager effectManager;
         private Constants.Scene currentScene;
         private bool initialized = false;
         private bool isActive = false;
@@ -54,6 +57,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     meidoManager.Update();
                     environmentManager.Update();
                     windowManager.Update();
+                    effectManager.Update();
                 }
             }
         }
@@ -135,6 +139,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             meidoManager = new MeidoManager();
             environmentManager = new EnvironmentManager(meidoManager);
             messageWindowManager = new MessageWindowManager();
+            lightManager = new LightManager();
+            propManager = new PropManager(meidoManager);
+            effectManager = new EffectManager();
 
             MaidSwitcherPane maidSwitcherPane = new MaidSwitcherPane(meidoManager);
 
@@ -145,8 +152,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     [Constants.Window.Call] = new CallWindowPane(meidoManager),
                     [Constants.Window.Pose] = new PoseWindowPane(meidoManager, maidSwitcherPane),
                     [Constants.Window.Face] = new FaceWindowPane(meidoManager, maidSwitcherPane),
-                    [Constants.Window.BG] = new BGWindowPane(environmentManager),
-                    [Constants.Window.BG2] = new BG2WindowPane(meidoManager, environmentManager)
+                    [Constants.Window.BG] = new BGWindowPane(environmentManager, lightManager, effectManager),
+                    [Constants.Window.BG2] = new BG2WindowPane(meidoManager, propManager)
                 },
                 [Constants.Window.Message] = new MessageWindow(messageWindowManager)
             };
@@ -163,6 +170,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             meidoManager.Activate();
             environmentManager.Activate();
+            propManager.Activate();
+            lightManager.Activate();
+            effectManager.Activate();
             windowManager.Activate();
             messageWindowManager.Activate();
 
@@ -179,12 +189,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             meidoManager.Deactivate();
             environmentManager.Deactivate();
+            propManager.Deactivate();
+            lightManager.Deactivate();
+            effectManager.Deactivate();
             messageWindowManager.Deactivate();
             windowManager.Deactivate();
 
-            // GameMain.Instance.SoundMgr.PlayBGM("bgm009.ogg", 1f, true);
-            GameObject dailyPanel = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
-            dailyPanel.SetActive(true);
+            GameObject dailyPanel = GameObject.Find("UI Root")?.transform.Find("DailyPanel")?.gameObject;
+            dailyPanel?.SetActive(true);
         }
     }
 }