private void AttributeTypeField(AttributeDeclaration attribute, AttributeUsageType usage)
        {
            GUILayout.Label(" ", GUILayout.Height(20));
            var position = GUILayoutUtility.GetLastRect();

            Type[] types = new Type[] { };

            switch (usage)
            {
            case AttributeUsageType.Class:
                types = classAttributeTypes;
                break;

            case AttributeUsageType.Struct:
                types = structAttributeTypes;
                break;

            case AttributeUsageType.Enum:
                types = enumAttributeTypes;
                break;

            case AttributeUsageType.Interface:
                types = interfaceAttributeTypes;
                break;

            case AttributeUsageType.Field:
                types = fieldAttributeTypes;
                break;

            case AttributeUsageType.Property:
                types = propertyAttributeTypes;
                break;

            case AttributeUsageType.Method:
                types = methodAttributeTypes;
                break;
            }

            attribute.SetType(LudiqGUI.TypeField(position, GUIContent.none, attribute.GetAttributeType(), () =>
            {
                return(new TypeOptionTree(types));
            }));
        }
        protected override void OnGUI(Rect position, GUIContent label)
        {
            position = BeginBlock(metadata, position, label);

            var fieldPosition = new Rect
                                (
                position.x,
                position.y,
                position.width,
                EditorGUIUtility.singleLineHeight
                                );

            var newType = LudiqGUI.TypeField(fieldPosition, GUIContent.none, (Type)metadata.value, GetOptions);

            if (EndBlock(metadata))
            {
                metadata.RecordUndo();
                metadata.value = newType;
            }
        }
Example #3
0
        public void OnGUI(Rect position, GUIContent label, bool showLabels, ref float y)
        {
            if (parent.chooseType)
            {
                var x = position.x;
                var remainingWidth = position.width;

                if (showLabels)
                {
                    var typeLabel = label == GUIContent.none ? new GUIContent("Type") : new GUIContent(label.text + " Type");

                    var typeLabelPosition = new Rect
                                            (
                        x,
                        y,
                        SystemObjectInspector.Styles.labelWidth,
                        EditorGUIUtility.singleLineHeight
                                            );

                    GUI.Label(typeLabelPosition, typeLabel, Inspector.ProcessLabelStyle(parent.metadata, null));

                    x += typeLabelPosition.width;
                    remainingWidth -= typeLabelPosition.width;
                }

                var typePosition = new Rect
                                   (
                    x,
                    y,
                    remainingWidth,
                    EditorGUIUtility.singleLineHeight
                                   );

                EditorGUI.BeginChangeCheck();

                var newType = LudiqGUI.TypeField(typePosition, GUIContent.none, parent.type, GetTypeOptions, new GUIContent("(Null)"));

                if (EditorGUI.EndChangeCheck())
                {
                    parent.metadata.RecordUndo();
                    parent.type = newType;
                    parent.SetValue();
                    parent.SetHeightDirty();
                }

                y += typePosition.height;
            }

            if (parent.chooseType && parent.showValue)
            {
                y += SystemObjectInspector.Styles.spaceBetweenTypeAndValue;
            }

            if (parent.showValue)
            {
                Rect valuePosition;

                if (parent.chooseType)
                {
                    var x = position.x;
                    var remainingWidth = position.width;

                    if (showLabels)
                    {
                        var valueLabel = label == GUIContent.none ? new GUIContent("Value") : new GUIContent(label.text + " Value");

                        var valueLabelPosition = new Rect
                                                 (
                            x,
                            y,
                            SystemObjectInspector.Styles.labelWidth,
                            EditorGUIUtility.singleLineHeight
                                                 );

                        GUI.Label(valueLabelPosition, valueLabel, Inspector.ProcessLabelStyle(parent.metadata, null));

                        x += valueLabelPosition.width;
                        remainingWidth -= valueLabelPosition.width;
                    }

                    valuePosition = new Rect
                                    (
                        x,
                        y,
                        remainingWidth,
                        EditorGUIUtility.singleLineHeight
                                    );

                    LudiqGUI.Inspector(parent.metadata.Cast(parent.type), valuePosition, GUIContent.none);
                }
                else
                {
                    valuePosition = new Rect
                                    (
                        position.x,
                        y,
                        position.width,
                        LudiqGUI.GetInspectorHeight(parent, parent.metadata.Cast(parent.type), position.width, label)
                                    );

                    LudiqGUI.Inspector(parent.metadata.Cast(parent.type), valuePosition, label);
                }

                y += valuePosition.height;
            }
            else
            {
                parent.metadata.value = null;
            }
        }
        protected override void OnGUI(Rect position, GUIContent label)
        {
            // Super hacky hotfix:
            // If the value changes in between OnGUI calls,
            // the OnValueChange event will not be called, because
            // we don't even look at the value until showField is true.
            // For example, an object that was null and becomes non-null
            // will be reset to null by the inspector unless this line is here,
            // because type will be null and showField will thus be false.
            var haxHotfix = metadata.value;
            // TL;DR: storing a local private type field that does not
            // take the actual, current variable type into consideration is a
            // very bad idea and will inevitably cause inspector v. codebase fighting
            // or inspector v. inspector fighting.

            var showLabels = !adaptiveWidth && position.width >= 120;

            BeginBlock(metadata, position, GUIContent.none);

            if (chooseType)
            {
                var x = position.x;
                var remainingWidth = position.width;

                if (showLabels)
                {
                    var typeLabel = label == GUIContent.none ? new GUIContent("Type") : new GUIContent(label.text + " Type");

                    var typeLabelPosition = new Rect
                                            (
                        x,
                        y,
                        Styles.labelWidth,
                        EditorGUIUtility.singleLineHeight
                                            );

                    GUI.Label(typeLabelPosition, typeLabel, ProcessLabelStyle(metadata, null));

                    x += typeLabelPosition.width;
                    remainingWidth -= typeLabelPosition.width;
                }

                var typePosition = new Rect
                                   (
                    x,
                    y,
                    remainingWidth,
                    EditorGUIUtility.singleLineHeight
                                   );

                EditorGUI.BeginChangeCheck();

                var newType = LudiqGUI.TypeField(typePosition, GUIContent.none, type, GetTypeOptions, new GUIContent("(Null)"));

                if (EditorGUI.EndChangeCheck())
                {
                    metadata.RecordUndo();
                    type = newType;
                    EnforceType();
                    SetHeightDirty();
                }

                y += typePosition.height;
            }

            if (chooseType && showValue)
            {
                y += Styles.spaceBetweenTypeAndValue;
            }

            if (showValue)
            {
                Rect valuePosition;

                if (chooseType)
                {
                    var x = position.x;
                    var remainingWidth = position.width;

                    if (showLabels)
                    {
                        var valueLabel = label == GUIContent.none ? new GUIContent("Value") : new GUIContent(label.text + " Value");

                        var valueLabelPosition = new Rect
                                                 (
                            x,
                            y,
                            Styles.labelWidth,
                            EditorGUIUtility.singleLineHeight
                                                 );

                        GUI.Label(valueLabelPosition, valueLabel, ProcessLabelStyle(metadata, null));

                        x += valueLabelPosition.width;
                        remainingWidth -= valueLabelPosition.width;
                    }

                    valuePosition = new Rect
                                    (
                        x,
                        y,
                        remainingWidth,
                        EditorGUIUtility.singleLineHeight
                                    );

                    LudiqGUI.Inspector(metadata.Cast(type), valuePosition, GUIContent.none);
                }
                else
                {
                    valuePosition = new Rect
                                    (
                        position.x,
                        y,
                        position.width,
                        LudiqGUI.GetInspectorHeight(this, metadata.Cast(type), position.width, label)
                                    );

                    LudiqGUI.Inspector(metadata.Cast(type), valuePosition, label);
                }

                y += valuePosition.height;
            }
            else
            {
                metadata.value = null;
            }

            EndBlock(metadata);
        }