예제 #1
0
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (DecoratorDrawers != null && !IsCurrentlyNested)
            {
                foreach (var decorator in DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (PropertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                PropertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtilityHelper.TempContent(property.displayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EasyGUI.DefaultPropertyField(position, property, label));
                }
                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EasyGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EasyGUI.DefaultPropertyField(position, prop, label) && EasyGUI.HasVisibleChildFields(prop);
                position.y += position.height + EasyGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop, null);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, false);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, false) && EasyGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EasyGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
        /// <summary>
        /// Handle the Drawing of a given property, within a given position rect.
        /// </summary>
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            // Keep track of the height we have available to draw this property after decorator drawers
            float heighRemaining = position.height;

            position.height = 0f;

            // Handle Decorator Drawers for non-nested properties
            if (decoratorDrawers != null && !IsCurrentlyNested)
            {
                foreach (DecoratorDrawer decoratorDrawer in decoratorDrawers)
                {
                    position.height = decoratorDrawer.GetHeight();

                    float labelWidth = EditorGUIUtility.labelWidth;
                    float fieldWidth = EditorGUIUtility.fieldWidth;

                    // Draw the decorator with its default OnGUI
                    decoratorDrawer.OnGUI(position);

                    EditorGUIUtility.labelWidth = labelWidth;
                    EditorGUIUtility.fieldWidth = fieldWidth;

                    position.y     += position.height;
                    heighRemaining -= position.height;
                }
            }

            position.height = heighRemaining;

            // Handle Property drawers
            if (PropertyDrawer != null)
            {
                float labelWidth = EditorGUIUtility.labelWidth;
                float fieldWidth = EditorGUIUtility.fieldWidth;

                GUIContent curLabel = label ?? StratusEditorUtility.TempContent(property.displayName);
                PropertyDrawer.OnGUISafe(position, property.Copy(), curLabel);

                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUIUtility.fieldWidth = fieldWidth;
                return(false);
            }

            position.height = StratusEditorUtility.GetSinglePropertyHeight(property, label);
            bool isVisible = StratusEditorUtility.DefaultPropertyField(position, property, label);

            position.y += position.height;

            // No children - we're done
            if (!includeChildren)
            {
                return(isVisible);
            }

            // Handle Children
            if (isVisible && StratusEditorUtility.HasVisibleChildFields(property))
            {
                Vector2 localIconSize    = EditorGUIUtility.GetIconSize();
                bool    localEnabled     = GUI.enabled;
                int     localIndentLevel = EditorGUI.indentLevel;

                SerializedProperty begin = null;
                SerializedProperty end   = null;

                // Array/List: Get paginated begin/end, draw header, and update position to where paginated elements should be drawn
                if (property.isArray)
                {
                    //Redacted.PaginatedArrayUtilities.GetPagePropertyRange(property, ref begin, ref end);

                    //SerializedProperty sizeProperty = property.Copy();
                    //sizeProperty.NextVisible(true);

                    //EditorGUI.BeginChangeCheck();
                    //Rect headerRect = Redacted.PaginatedArrayUtilities.HandleArrayHeader(position, sizeProperty);
                    //if (EditorGUI.EndChangeCheck())
                    //  return false;
                    //
                    //position.y += headerRect.height;
                    //position.height -= headerRect.height;
                }
                // Default: Just get first and last child
                else
                {
                    begin = property.Copy();
                    begin.NextVisible(true);
                    end = property.GetEndProperty();
                }

                // Draw all nested properties from begin to end
                if (begin != null && end != null)
                {
                    position = DrawPropertyNestedRange(position, EditorGUI.indentLevel - property.depth, begin, end);
                }

                EditorGUIUtility.SetIconSize(localIconSize);
                GUI.enabled           = localEnabled;
                EditorGUI.indentLevel = localIndentLevel;
            }

            return(false);
        }