Browse Source

Add OnDestroy to ensure gizmo is destroyed

habeebweeb 4 years ago
parent
commit
a8512bf2ff
1 changed files with 10 additions and 5 deletions
  1. 10 5
      COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/BaseDrag.cs

+ 10 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/BaseDrag.cs

@@ -63,20 +63,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.maid = maid;
             this.position = position;
             this.rotation = rotation;
-            dragPointRenderer = GetComponent<Renderer>();
-            dragPointCollider = GetComponent<Collider>();
-            dragPointRenderer.enabled = true;
+            this.dragPointRenderer = GetComponent<Renderer>();
+            this.dragPointCollider = GetComponent<Collider>();
+            this.dragPointRenderer.enabled = true;
 
             isPlaying = maid.GetAnimation().isPlaying;
         }
 
         protected void InitializeGizmo(GameObject target, float scale = 0.25f)
         {
-            gizmo = target.gameObject.AddComponent<GizmoRender>();
+            gizmo = target.AddComponent<GizmoRender>();
             gizmo.eRotate = true;
             gizmo.offsetScale = scale;
             gizmo.lineRSelectedThick = 0.25f;
-            gizmo.Visible = false;
+            GizmoVisible = false;
         }
 
         protected void InitializeGizmo(Transform target, float scale = 0.25f)
@@ -159,6 +159,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
+        private void OnDestroy()
+        {
+            GameObject.Destroy(gizmo);
+        }
+
         protected void OnDragEvent()
         {
             DragEvent?.Invoke(null, EventArgs.Empty);