Browse Source

Add shadow casting toggle for props

habeebweeb 4 years ago
parent
commit
32e3c14a7f

+ 1 - 0
COM3D2.MeidoPhotoStudio.Plugin/Config/MeidoPhotoStudio/Translations/en/translation.ui.json

@@ -216,6 +216,7 @@
     "propManagerPane": {
         "dragPointToggle": "Cube",
         "gizmoToggle": "Gizmo",
+        "shadowCastingToggle": "Shadow",
         "copyButton": "Copy",
         "deleteButton": "Delete"
     },

+ 25 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/DragPoint/DragPointOther.cs

@@ -1,4 +1,6 @@
+using System.Collections.Generic;
 using UnityEngine;
+using UnityEngine.Rendering;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
@@ -23,9 +25,32 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
     internal class DragPointDogu : DragPointGeneral
     {
+        private List<Renderer> meshRenderers;
         public AttachPointInfo attachPointInfo = AttachPointInfo.Empty;
         public string Name => MyGameObject.name;
         public string assetName = string.Empty;
+        public bool ShadowCasting
+        {
+            get
+            {
+                if (meshRenderers.Count == 0) return false;
+                return meshRenderers[0].shadowCastingMode == ShadowCastingMode.On;
+            }
+            set
+            {
+                foreach (Renderer renderer in meshRenderers)
+                {
+                    renderer.shadowCastingMode = value ? ShadowCastingMode.On : ShadowCastingMode.Off;
+                }
+            }
+        }
+
+        public override void Set(Transform myObject)
+        {
+            base.Set(myObject);
+            meshRenderers = new List<Renderer>(MyObject.GetComponentsInChildren<SkinnedMeshRenderer>());
+            meshRenderers.AddRange(MyObject.GetComponentsInChildren<MeshRenderer>());
+        }
 
         protected override void ApplyDragType()
         {

+ 14 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindow2Panes/PropManagerPane.cs

@@ -10,6 +10,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Button nextPropButton;
         private Toggle dragPointToggle;
         private Toggle gizmoToggle;
+        private Toggle shadowCastingToggle;
         private Button deletePropButton;
         private Button copyPropButton;
         private int CurrentDoguIndex => this.propManager.CurrentDoguIndex;
@@ -59,6 +60,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 this.propManager.CurrentDogu.GizmoEnabled = gizmoToggle.Value;
             };
 
+            this.shadowCastingToggle = new Toggle(Translation.Get("propManagerPane", "shadowCastingToggle"));
+            this.shadowCastingToggle.ControlEvent += (s, a) =>
+            {
+                if (this.updating || this.propManager.DoguCount == 0) return;
+                this.propManager.CurrentDogu.ShadowCasting = this.shadowCastingToggle.Value;
+            };
+
             this.copyPropButton = new Button(Translation.Get("propManagerPane", "copyButton"));
             this.copyPropButton.ControlEvent += (s, a) => this.propManager.CopyDogu(CurrentDoguIndex);
 
@@ -70,6 +78,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             this.dragPointToggle.Label = Translation.Get("propManagerPane", "dragPointToggle");
             this.gizmoToggle.Label = Translation.Get("propManagerPane", "gizmoToggle");
+            this.shadowCastingToggle.Label = Translation.Get("propManagerPane", "shadowCastingToggle");
             this.copyPropButton.Label = Translation.Get("propManagerPane", "copyButton");
             this.deletePropButton.Label = Translation.Get("propManagerPane", "deleteButton");
         }
@@ -108,6 +117,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.deletePropButton.Draw(noExpandWidth);
             GUILayout.EndHorizontal();
 
+            GUILayout.BeginHorizontal();
+            this.shadowCastingToggle.Draw(noExpandWidth);
+            GUILayout.EndHorizontal();
+
             GUI.enabled = true;
         }
 
@@ -126,6 +139,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.updating = true;
             this.dragPointToggle.Value = dogu.DragPointEnabled;
             this.gizmoToggle.Value = dogu.GizmoEnabled;
+            this.shadowCastingToggle.Value = dogu.ShadowCasting;
             this.updating = false;
         }
     }