Esempio n. 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!Initialise(property))
            {
                return;
            }

            Rect originalPosition = position;

            position.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.PropertyScope(position, GUIContent.none, property))
            {
                if (EditorGUIUtils.DrawHeaderWithFoldout(position, label, property.isExpanded, noBoldOrIndent: true))
                {
                    property.isExpanded = !property.isExpanded;
                }
            }

            if (!property.isExpanded)
            {
                return;
            }

            originalPosition.yMin  = position.yMax;
            originalPosition.xMin += 10;
            EditorGUIUtils.DrawOutline(originalPosition, 1);

            position.xMin += 15;             //Indent
            position.xMax -= 4;
            position.y     = position.yMax + EditorGUIUtility.standardVerticalSpacing * 2;

            SerializedProperty values = property.FindPropertyRelative("values");

            values.arraySize = enumNames.Length;
            float contentX     = position.x + EditorGUIUtility.labelWidth;
            float contentWidth = position.width - EditorGUIUtility.labelWidth;

            for (int i = hidesFirstEnum ? 1 : 0; i < enumNames.Length; i++)
            {
                SerializedProperty value = values.GetArrayElementAtIndex(i);
                Rect labelRect           = new Rect(position.x, position.y, EditorGUIUtility.labelWidth - 4, position.height);
                Rect contentRect         = new Rect(contentX, position.y, contentWidth, position.height);
                if (multiLine)
                {
                    Rect r = new Rect(position.x - 5, contentRect.y - 2, position.width + 8, contentRect.height + 2);
                    EditorGUI.DrawRect(r, EditorGUIUtils.HeaderColor);

                    labelRect.xMin += 12;

                    using (new EditorGUI.PropertyScope(r, GUIContent.none, value))
                    {
                        GUI.enabled = false;
                        EditorGUI.Popup(labelRect, i, enumNames);
                        GUI.enabled = true;
                    }

                    EditorGUI.LabelField(labelRect, tooltips[i]);

                    //Foldout
                    value.isExpanded = EditorGUI.Foldout(new Rect(r.x + 15, r.y, r.width, r.height), value.isExpanded, GUIContent.none, true);

                    contentRect.y = labelRect.yMax + EditorGUIUtility.standardVerticalSpacing;
                    if (!value.isExpanded)
                    {
                        EditorGUI.DrawRect(new Rect(r.x, labelRect.yMax, r.width, 1), EditorGUIUtils.SplitterColor);
                        position.y = contentRect.y;
                        continue;
                    }

                    SerializedProperty end = value.GetEndProperty();
                    int  index             = 0;
                    bool enterChildren     = true;
                    while (value.NextVisible(enterChildren) && !SerializedProperty.EqualContents(value, end))
                    {
                        float height = propertyHeights[index++];
                        contentRect.height = height;
                        using (new EditorGUI.PropertyScope(new Rect(position.x, contentRect.y, position.width, contentRect.height), GUIContent.none, value))
                        {
                            float labelRectX = labelRect.x + 15;
                            GUI.Label(new Rect(labelRectX, contentRect.y, contentRect.x - labelRectX - 2, contentRect.height), value.displayName);
                            EditorGUI.PropertyField(contentRect, value, GUIContent.none, false);
                        }

                        contentRect.y += height + EditorGUIUtility.standardVerticalSpacing;
                        enterChildren  = false;
                    }
                }
                else
                {
                    GUI.enabled = false;
                    EditorGUI.Popup(labelRect, i, enumNames);
                    GUI.enabled = true;
                    EditorGUI.LabelField(labelRect, tooltips[i]);

                    Color lastColor = GUI.color;
                    if (value.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        if (value.objectReferenceValue == null)
                        {
                            GUI.color *= new Color(1f, 0.46f, 0.51f);
                        }
                    }

                    using (new EditorGUI.PropertyScope(new Rect(position.x, contentRect.y, position.width, contentRect.height), GUIContent.none, value))
                        EditorGUI.PropertyField(contentRect, value, GUIContent.none);
                    contentRect.y += propertyHeights[0] + EditorGUIUtility.standardVerticalSpacing;
                    GUI.color      = lastColor;
                }

                position.y = contentRect.yMin;
            }
        }