Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if UNITY_EDITOR
- internal virtual Rect GUIDrawElement(Rect rect, SerializedProperty serializedProperty, bool isActive, bool isFocused)
- {
- if (serializedProperty == null)
- {
- EditorGUI.HelpBox(rect, "SerializedProperty was null!", MessageType.Error);
- return rect;
- }
- serializedProperty = serializedProperty.Copy();
- int startingDepth = serializedProperty.depth;
- var currentRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
- EditorGUI.LabelField(currentRect, serializedProperty.boxedValue.GetType().Name);
- var first = true;
- while (serializedProperty.NextVisible(EnterChildren(serializedProperty, first)) && serializedProperty.depth > startingDepth)
- {
- first = false;
- currentRect = currentRect.MoveDownFor(EditorGUI.GetPropertyHeight(serializedProperty));
- if (serializedProperty.propertyType == SerializedPropertyType.Generic && !serializedProperty.isArray)
- currentRect = currentRect.CutFromTop(EditorGUIUtility.singleLineHeight)[0];
- EditorGUI.indentLevel = serializedProperty.depth;
- EditorGUI.PropertyField(currentRect, serializedProperty);
- }
- return currentRect;
- static bool EnterChildren(SerializedProperty serializedProperty, bool first)
- {
- return first || (
- serializedProperty.propertyType == SerializedPropertyType.Generic
- && !serializedProperty.isArray
- && serializedProperty.isExpanded
- );
- }
- }
- internal virtual float GUIElementHeight(SerializedProperty serializedProperty)
- {
- serializedProperty = serializedProperty.Copy();
- int startingDepth = serializedProperty.depth;
- float height = EditorGUIUtility.singleLineHeight * 2;
- var first = true;
- while (serializedProperty.NextVisible(first) && serializedProperty.depth > startingDepth)
- {
- first = false;
- height += EditorGUI.GetPropertyHeight(serializedProperty);
- }
- return height;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement