Skip to content

Commit

Permalink
Merge pull request #74 from codewriter-packages/add-steps-collapse-bu…
Browse files Browse the repository at this point in the history
…ttons

Add ExpandAllSeps and CollapseAllSteps buttons in inspector
  • Loading branch information
brunomikoski authored Dec 14, 2023
2 parents 314845f + 7d3cf51 commit c676b58
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions Scripts/Editor/Core/AnimationSequencerControllerCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace BrunoMikoski.AnimationSequencer
[CustomEditor(typeof(AnimationSequencerController), true)]
public class AnimationSequencerControllerCustomEditor : Editor
{
private static readonly GUIContent CollapseAllAnimationStepsContent = new GUIContent("▸◂", "Collapse all animation steps");
private static readonly GUIContent ExpandAllAnimationStepsContent = new GUIContent("◂▸", "Expand all animation steps");

private ReorderableList reorderableList;

private AnimationSequencerController sequencerController;
Expand Down Expand Up @@ -183,7 +186,32 @@ public override void OnInspectorGUI()
DrawFoldoutArea("Settings", ref showSettingsPanel, DrawSettings);
DrawFoldoutArea("Callback", ref showCallbacksPanel, DrawCallbacks);
DrawFoldoutArea("Preview", ref showPreviewPanel, DrawPreviewControls);
DrawFoldoutArea("Steps", ref showStepsPanel, DrawAnimationSteps);
DrawFoldoutArea("Steps", ref showStepsPanel, DrawAnimationSteps, DrawAnimationStepsHeader, 50);
}

private void DrawAnimationStepsHeader(Rect rect)
{
var collapseAllRect = new Rect(rect)
{
xMin = rect.xMax - 50,
xMax = rect.xMax - 25,
};

var expandAllRect = new Rect(rect)
{
xMin = rect.xMax - 25,
xMax = rect.xMax - 0,
};

if (GUI.Button(collapseAllRect, CollapseAllAnimationStepsContent, EditorStyles.miniButtonLeft))
{
SetStepsExpanded(false);
}

if (GUI.Button(expandAllRect, ExpandAllAnimationStepsContent, EditorStyles.miniButtonRight))
{
SetStepsExpanded(true);
}
}

private void DrawAnimationSteps()
Expand Down Expand Up @@ -518,22 +546,36 @@ private void DrawTimeScaleSlider()
GUILayout.FlexibleSpace();
}

private void DrawFoldoutArea(string title,ref bool foldout, Action additionalInspectorGUI)
private void DrawFoldoutArea(string title, ref bool foldout, Action additionalInspectorGUI,
Action<Rect> additionalHeaderGUI = null, float additionalHeaderWidth = 0)
{
using (new EditorGUILayout.VerticalScope("FrameBox"))
{
Rect rect = EditorGUILayout.GetControlRect();
rect.x += 10;
rect.width -= 10;
rect.y -= 4;

foldout = EditorGUI.Foldout(rect, foldout, title);


var foldoutRect = new Rect(rect)
{
xMax = rect.xMax - additionalHeaderWidth,
};

var additionalHeaderRect = new Rect(rect)
{
xMin = foldoutRect.xMax,
};

foldout = EditorGUI.Foldout(foldoutRect, foldout, title);

if (foldout)
{
additionalHeaderGUI?.Invoke(additionalHeaderRect);
additionalInspectorGUI.Invoke();
}
}
}

private void OnDrawAnimationStep(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(index);
Expand Down Expand Up @@ -577,6 +619,15 @@ private float GetAnimationStepHeight(int index)
return element.GetPropertyDrawerHeight();
}

private void SetStepsExpanded(bool expanded)
{
SerializedProperty animationStepsProperty = reorderableList.serializedProperty;
for (int i = 0; i < animationStepsProperty.arraySize; i++)
{
animationStepsProperty.GetArrayElementAtIndex(i).isExpanded = expanded;
}
}

private void SetDefaults()
{
sequencerController = target as AnimationSequencerController;
Expand Down

0 comments on commit c676b58

Please sign in to comment.