From 552e1534a43fd440937223cf95916966d1b65705 Mon Sep 17 00:00:00 2001 From: Santiago Ariel Mansilla <56666653+Gann4Life@users.noreply.github.com> Date: Wed, 12 Jul 2023 09:38:38 -0300 Subject: [PATCH] Add *delete all* functionality --- .../Scripts/Editor/RagdollFactoryEditor.cs | 47 +++++++++---------- .../Scripts/States/RFComponentState.cs | 7 +++ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Gann4Games/Ragdoll Factory/Scripts/Editor/RagdollFactoryEditor.cs b/Gann4Games/Ragdoll Factory/Scripts/Editor/RagdollFactoryEditor.cs index d875184..d451417 100644 --- a/Gann4Games/Ragdoll Factory/Scripts/Editor/RagdollFactoryEditor.cs +++ b/Gann4Games/Ragdoll Factory/Scripts/Editor/RagdollFactoryEditor.cs @@ -67,7 +67,6 @@ private void OnEnable() private void LoadButtonIcons() { - int iconSize = 5; iconAdd = EditorGUIUtility.Load(iconAddPath) as Texture2D; iconSelect = EditorGUIUtility.Load(iconSelectPath) as Texture2D; iconDelete = EditorGUIUtility.Load(iconDeletePath) as Texture2D; @@ -107,6 +106,7 @@ public override void OnInspectorGUI() serializedObject.Update(); DrawInspectorTabs(); DrawCurrentComponentProperties(); + DrawActionButtons(); serializedObject.ApplyModifiedProperties(); } @@ -154,61 +154,60 @@ private void DrawCurrentComponentProperties() } private void DrawRigidbodyProperties() { - if(!(_target.CurrentComponent is RigidbodyComponentState)) return; + // if(!(_target.CurrentComponent is RigidbodyComponentState)) return; EditorGUILayout.PropertyField(_rigidbodyMass); EditorGUILayout.PropertyField(_rigidbodyDrag); EditorGUILayout.PropertyField(_rigidbodyAngularDrag); EditorGUILayout.PropertyField(_rigidbodyUseGravity); EditorGUILayout.PropertyField(_rigidbodyIsKinematic); - - if(GUILayout.Button("Delete Rigidbody")) - _target.CurrentComponent.Delete(); //.DeleteSelectedRigidbody(); } private void DrawJointProperties() { - if(!(_target.CurrentComponent is ConfigurableJointComponentState)) return; + // if(!(_target.CurrentComponent is ConfigurableJointComponentState)) return; EditorGUILayout.PropertyField(_jointAxis); EditorGUILayout.PropertyField(_jointLowXLimit); EditorGUILayout.PropertyField(_jointHighXLimit); EditorGUILayout.PropertyField(_jointYLimit); EditorGUILayout.PropertyField(_jointZAngle); - - if (GUILayout.Button("Delete Joint")) - _target.CurrentComponent.Delete();//.DeleteSelectedJoint(); } private void DrawCapsuleColliderProperties() { - if(!(_target.CurrentComponent is CapsuleColliderComponentState)) return; + // if(!(_target.CurrentComponent is CapsuleColliderComponentState)) return; EditorGUILayout.PropertyField(_capsuleLength); EditorGUILayout.PropertyField(_capsuleRadius); - - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button("Convert to Box Collider")) - _target.CurrentComponent.ConvertTo(new BoxCollider());//.ConvertSelectedColliderToBox(); - if (GUILayout.Button("Delete")) - _target.CurrentComponent.Delete();//.DeleteSelectedCollider(); - EditorGUILayout.EndHorizontal(); } private void DrawBoxColliderProperties() { - if(!(_target.CurrentComponent is BoxColliderComponentState)) return; + // if(!(_target.CurrentComponent is BoxColliderComponentState)) return; EditorGUILayout.PropertyField(_boxLength); EditorGUILayout.PropertyField(_boxWidth); EditorGUILayout.PropertyField(_boxDepth); + } + #endregion + + private void DrawActionButtons() + { + bool hasSelection = _target.CurrentComponent.HasComponentSelected; + bool isCapsule = _target.CurrentComponent is CapsuleColliderComponentState && hasSelection; + bool isBox = _target.CurrentComponent is BoxColliderComponentState && hasSelection; - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button("Convert to Capsule Collider")) + if (isBox && GUILayout.Button("Convert to Capsule Collider")) _target.CurrentComponent.ConvertTo(new CapsuleCollider());//.ConvertSelectedColliderToCapsule(); - if (GUILayout.Button("Delete")) - _target.CurrentComponent.Delete();//.DeleteSelectedCollider(); + if (isCapsule && GUILayout.Button("Convert to Box Collider")) + _target.CurrentComponent.ConvertTo(new BoxCollider());//.ConvertSelectedColliderToBox(); + + EditorGUILayout.BeginHorizontal(); + if(GUILayout.Button("Delete All")) + _target.CurrentComponent.DeleteAll(); + if (hasSelection && GUILayout.Button("Delete Selected")) + _target.CurrentComponent.Delete(); EditorGUILayout.EndHorizontal(); } - #endregion - + /// /// Shows relevant information about how to perfom a specific action in the choosen tool/button/mode /// diff --git a/Gann4Games/Ragdoll Factory/Scripts/States/RFComponentState.cs b/Gann4Games/Ragdoll Factory/Scripts/States/RFComponentState.cs index bd16ee2..112d270 100644 --- a/Gann4Games/Ragdoll Factory/Scripts/States/RFComponentState.cs +++ b/Gann4Games/Ragdoll Factory/Scripts/States/RFComponentState.cs @@ -37,6 +37,7 @@ public virtual void Delete() ComponentList.Remove(SelectedComponent); Undo.DestroyObjectImmediate(SelectedComponent); } + /// /// Selects an element and then deletes it. /// @@ -46,6 +47,12 @@ public void Delete(Component component) Select(component); Delete(); } + + public void DeleteAll() + { + while (ComponentList.Count > 0) + Delete(ComponentList[0]); + } /// /// Deletes the game object from the selected component and removes it from the history.