gasgiant / Markup-Attributes

A Unity Editor extension for customizing inspector layout with attributes.
MIT License
289 stars 11 forks source link

Is there any way to use the MarkupGUI methods when making custom propertydrawers? #16

Closed peter-mills-dev closed 9 months ago

peter-mills-dev commented 1 year ago

I'm getting errors when trying to use any of these tools to make a property drawer.

ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint

Is there something I'm missing to make this work? I've tried to get a minimal version working with the sample from the documentation.

  public class ExamplePropertyDrawer :  PropertyDrawer
    {        
        MarkupGUI.GroupsStack groupsStack = new MarkupGUI.GroupsStack();
        int activeTab = 0;
        bool foldout = true;

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //EditorGUI.PropertyField(position, property, label, true);

            // Always clear the groups stack.
            groupsStack.Clear();

            groupsStack += MarkupGUI.BeginBoxGroup("Box");
            // group contents ...
            groupsStack.EndGroup();

            groupsStack += MarkupGUI.BeginTitleGroup("TitleGroup", true);
            // group contents ...
            groupsStack.EndGroup();

            groupsStack += MarkupGUI.BeginFoldoutGroup(ref foldout, "Foldout");
            // group contents ...
            groupsStack.EndGroup();

            groupsStack += MarkupGUI.BeginTabsGroup(ref activeTab, 
                new string[] { "Left", "Middle", "Right" }, true);
            // group contents ...

            // Always end all groups at the end.
            groupsStack.EndAll();
        }
    }
gasgiant commented 1 year ago

Hi! MarkupGUI uses EditorGUILayout under the hood, which is not really supported in property drawers. I think you can use it, but only if the object with the property has a custom editor (see https://answers.unity.com/questions/661360/finally-a-solution-cant-use-guilayout-stuff-in-pro.html)