Пример #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label.tooltip = EditorHelper.GetTooltipFromAttribute(fieldInfo, label.tooltip);

            bool  enabled = GUI.enabled;
            Color color   = GUI.color;

            if (IsReadOnly(property))
            {
                GUI.enabled = false;
            }

            if (!Validate(property))
            {
                GUI.color = errorColor;
            }

            using (var titles = TempList <string> .Get())
            {
                GetTitles(property, titles.buffer);

                string title = JoinTitle(titles.buffer);

                if (!string.IsNullOrEmpty(title))
                {
                    content.text = title;
                    float titleHeight = GetTitleHeight(title);

                    Rect titleRect = position;
                    titleRect.height = titleHeight;
                    EditorGUIHelper.Indent(ref titleRect, steps: EditorGUI.indentLevel);
                    GUI.Label(titleRect, content);
                    position.y      += titleHeight;
                    position.height -= titleHeight;
                }

                if (!UseObjField(property))
                {
                    EditorGUI.PropertyField(position, property, label, includeChildren: true);
                }
                else
                {
                    property.objectReferenceValue = EditorGUI.ObjectField(
                        position,
                        label,
                        property.objectReferenceValue,
                        GetObjRefType(),
                        allowSceneObjects: attribute.objRefRestriction != PropObjRefRestrict.OnlyAsset
                        );
                }
            }

            GUI.color   = color;
            GUI.enabled = enabled;
        }
Пример #2
0
        void DrawWithoutEditor(Rect position, SerializedProperty property)
        {
            Rect foldoutRect = position;

            foldoutRect.width   = 20.0f;
            property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, "");

            if (!property.isExpanded)
            {
                return;
            }

            position.y += position.height;

            if (property.isArray)
            {
                position.height = EditorGUIUtility.singleLineHeight;
                Rect sizeRect = position;
                EditorGUIHelper.Indent(ref sizeRect);

                property.arraySize = EditorGUI.IntField(sizeRect, "Size", property.arraySize);

                position.y += position.height;
            }

            EditorGUIHelper.Indent(ref position);

            Iterate(property,
                    foreachArrayElem: (SerializedProperty eleProp) =>
            {
                position.height = EditorGUI.GetPropertyHeight(eleProp);

                EditorGUI.PropertyField(position, eleProp, includeChildren: false);

                if (eleProp.objectReferenceValue != null)
                {
                    foldoutRect        = position;
                    foldoutRect.width  = 20.0f;
                    eleProp.isExpanded = EditorGUI.Foldout(foldoutRect, eleProp.isExpanded, "");
                }

                position.y += position.height;
            },
                    foreachChild: (SerializedProperty prop) =>
            {
                position.height = EditorGUI.GetPropertyHeight(prop);
                Rect indented   = position;
                EditorGUIHelper.Indent(ref indented);
                EditorGUI.PropertyField(indented, prop, includeChildren: true);
                position.y += position.height;
            }
                    );
        }
Пример #3
0
    // TODO: Might want to use PrefixLabel instead
    // A rect that should look like a standard Unity EditorGUI label
    // (i.e. the name before the value)
    // Returns position with the label's width deducted
    public static Rect StandardLabel(Rect position, GUIContent label)
    {
        EditorGUIHelper.Indent(ref position, EditorGUI.indentLevel);

        float labelWidth = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH;
        Rect  labelRect  = position;

        labelRect.width = labelWidth;
        GUI.Label(labelRect, label);

        position.x     += labelWidth;
        position.width -= labelWidth;

        return(position);
    }