Created
September 24, 2021 19:57
-
-
Save Schwapo/07635d70dfc6a1507e77f0db001cd02f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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