コード例 #1
0
        /// <summary>
        /// Draws property in default way but each single property is handled by custom action.
        /// 'Default way' means it will create foldout-based property if children are visible.
        /// Uses built-in layouting system.
        /// </summary>
        public static void DrawDefaultProperty(SerializedProperty property, GUIContent label,
                                               Action <SerializedProperty, GUIContent> drawParentAction, Action <SerializedProperty> drawElementAction)
        {
            if (!PropertyUtility.HasVisibleChildrenFields(property))
            {
                drawParentAction(property, label);
                return;
            }

            //draw standard foldout with built-in operations (like prefabs handling)
            //native steps to re-create:
            // - get foldout rect
            // - begin property using EditorGUI.BeginProperty method
            // - read current drag events
            // - draw foldout
            // - close property using EditorGUI.EndProperty method
            using (var propertyScope = new PropertyScope(property, label))
            {
                if (!propertyScope.IsVisible)
                {
                    return;
                }

                EditorGUI.indentLevel++;
                DrawPropertyChildren(property, drawElementAction);
                EditorGUI.indentLevel--;
            }
        }