Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExpandAllSeps and CollapseAllSteps buttons in inspector #74

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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