Exemplo n.º 1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label    = EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, label);

        EditorGUI.BeginChangeCheck();

        // Store old indent level and set it to 0, the PrefixLabel takes care of it
        int indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        float prevHeight = position.y - EditorGUIUtility.standardVerticalSpacing;
        var   propnames  = PropNames();
        var   props      = DisplayHelpers.Properties(property, propnames).ToArray();

        for (int ii = 0; ii < props.Length; ++ii)
        {
            var sp = props[ii];
            prevHeight += EditorGUIUtility.standardVerticalSpacing;
            var  myHeight = EditorGUI.GetPropertyHeight(sp, true);
            Rect r        = new Rect(position.x, prevHeight, position.width, myHeight);
            EditorGUI.PropertyField(r, sp, new GUIContent(propnames[ii]));
            prevHeight += myHeight;
        }

        if (EditorGUI.EndChangeCheck())
        {
            property.serializedObject.ApplyModifiedProperties();
        }

        EditorGUI.indentLevel = indent;
        EditorGUI.EndProperty();
    }
Exemplo n.º 2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label = EditorGUI.BeginProperty(position, label, property);
        var label_position = position;

        position = EditorGUI.PrefixLabel(position, label);

        EditorGUI.BeginChangeCheck();
        SerializedProperty enumVal = property.FindPropertyRelative(enumProperty);
        SerializedProperty duVal   = property.FindPropertyRelative(propName(enumVal.enumValueIndex));

        //int indent = EditorGUI.indentLevel;
        //EditorGUI.indentLevel = 0;

        float pw = position.width;
        float lw = label_position.width;

        float h1    = EditorGUI.GetPropertyHeight(enumVal);
        Rect  rect1 = new Rect(position.x, position.y, pw, h1);

        float prevHeight = position.y + h1; //Don't need to subtract vertical spacing since 1 is alreadyt required
        var   propnames  = OtherPropNames();
        var   props      = DisplayHelpers.Properties(property, propnames).ToArray();

        for (int ii = 0; ii < props.Length; ++ii)
        {
            var sp = props[ii];
            prevHeight += EditorGUIUtility.standardVerticalSpacing;
            var  myHeight = EditorGUI.GetPropertyHeight(sp, true);
            Rect r        = new Rect(label_position.x, prevHeight, lw, myHeight);
            EditorGUI.PropertyField(r, sp, new GUIContent(propnames[ii]));
            prevHeight += myHeight;
        }
        Rect rect2 = new Rect(label_position.x + lw * LabelOffset, prevHeight + EditorGUIUtility.standardVerticalSpacing,
                              lw * (1 - LabelOffset), EditorGUI.GetPropertyHeight(duVal, true));

        EditorGUI.PropertyField(rect1, enumVal, GUIContent.none);
        EditorGUI.PropertyField(rect2, duVal, GUIContent.none);

        if (EditorGUI.EndChangeCheck())
        {
            property.serializedObject.ApplyModifiedProperties();
        }

        //EditorGUI.indentLevel = indent;
        EditorGUI.EndProperty();
    }