Skip to content

Commit

Permalink
Add *delete all* functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Gann4Life committed Jul 12, 2023
1 parent fd6d4dc commit 552e153
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
47 changes: 23 additions & 24 deletions Gann4Games/Ragdoll Factory/Scripts/Editor/RagdollFactoryEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +106,7 @@ public override void OnInspectorGUI()
serializedObject.Update();
DrawInspectorTabs();
DrawCurrentComponentProperties();
DrawActionButtons();
serializedObject.ApplyModifiedProperties();
}

Expand Down Expand Up @@ -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


/// <summary>
/// Shows relevant information about how to perfom a specific action in the choosen tool/button/mode
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions Gann4Games/Ragdoll Factory/Scripts/States/RFComponentState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public virtual void Delete()
ComponentList.Remove(SelectedComponent);
Undo.DestroyObjectImmediate(SelectedComponent);
}

/// <summary>
/// Selects an element and then deletes it.
/// </summary>
Expand All @@ -46,6 +47,12 @@ public void Delete(Component component)
Select(component);
Delete();
}

public void DeleteAll()
{
while (ComponentList.Count > 0)
Delete(ComponentList[0]);
}

/// <summary>
/// Deletes the game object from the selected component and removes it from the history.
Expand Down

0 comments on commit 552e153

Please sign in to comment.