itsschwer / schwer-scripts

Open-source code for Unity
MIT License
1 stars 0 forks source link

Replace EditorGUILayout functions in InventoryDrawer #9

Open itsschwer opened 3 years ago

itsschwer commented 3 years ago

From the Unity documentation on PropertyDrawer:

Note that for performance reasons, EditorGUILayout functions are not usable with PropertyDrawers.

Despite seemingly working without error when inspecting InventorySO, other classes that have Inventory fields throw this error when inspected:

ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint
Aborting
UnityEngine.GUILayoutGroup.GetNext () (at <819de1aa368e45faa4f78e26c97c62b0>:0)
UnityEngine.GUILayoutUtility.DoGetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at <819de1aa368e45faa4f78e26c97c62b0>:0)
UnityEngine.GUILayoutUtility.GetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle style) (at <819de1aa368e45faa4f78e26c97c62b0>:0)
UnityEditor.EditorGUILayout.FoldoutInternal (System.Boolean foldout, UnityEngine.GUIContent content, System.Boolean toggleOnLabelClick, UnityEngine.GUIStyle style) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEditor.EditorGUILayout.Foldout (System.Boolean foldout, UnityEngine.GUIContent content, System.Boolean toggleOnLabelClick, UnityEngine.GUIStyle style) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEditor.EditorGUILayout.Foldout (System.Boolean foldout, System.String content, System.Boolean toggleOnLabelClick, UnityEngine.GUIStyle style) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEditor.EditorGUILayout.Foldout (System.Boolean foldout, System.String content, System.Boolean toggleOnLabelClick) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
SchwerEditor.ItemSystem.InventoryDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/_Schwer/SchwerScripts/ItemSystem/Editor/InventoryDrawer.cs:23)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

where Assets/_Schwer/SchwerScripts/ItemSystem/Editor/InventoryDrawer.cs:23 is property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, "Contents (" + keys.arraySize + ")", true); Commenting out this line just moves the error to the next EditorGUILayout function, as expected according to the docs.

itsschwer commented 3 years ago

A close to complete conversion is being worked on here. Refer to commit history of the linked file to see progress.

Last remaining issues are:

itsschwer commented 3 years ago

Spacing issue fixed by adding GUILayout.Space(kvpHeight + kvpSpacing); inside the for loop and GUILayout.Space(kvpSpacing); right after it (commit f2763dc).

Thanks Gungnir!