Skip to content

Instantly share code, notes, and snippets.

@Schwapo
Created September 24, 2021 19:57
Show Gist options
  • Save Schwapo/07635d70dfc6a1507e77f0db001cd02f to your computer and use it in GitHub Desktop.
Save Schwapo/07635d70dfc6a1507e77f0db001cd02f to your computer and use it in GitHub Desktop.
using Sirenix.OdinInspector;
using UnityEngine;
#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities.Editor;
#endif
public class UnityFoldoutGroupAttribute : PropertyGroupAttribute
{
public bool BoldLabel;
public UnityFoldoutGroupAttribute(string groupId, bool boldLabel = false)
: base(groupId) => BoldLabel = boldLabel;
public UnityFoldoutGroupAttribute(string groupId, float order, bool boldLabel)
: base(groupId, order) => BoldLabel = boldLabel;
}
#if UNITY_EDITOR
public class PropertySelectorGroupAttributeDrawer
: OdinGroupDrawer<UnityFoldoutGroupAttribute>
{
private GUIStyle foldoutStyle;
protected override void Initialize()
{
foldoutStyle = new GUIStyle("foldout")
{
fontStyle = Attribute.BoldLabel ? FontStyle.Bold : FontStyle.Normal
};
}
protected override void DrawPropertyLayout(GUIContent label)
{
Property.State.Expanded = SirenixEditorGUI.Foldout(
Property.State.Expanded, label, foldoutStyle);
if (Property.State.Expanded)
{
foreach (var child in Property.Children)
{
child.Draw(child.Label);
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment