Example #1
0
        public static float GetMinWidth(AssetListConfiguration.ColumnConfiguration column)
        {
            SerializedPropertyType propertyType = column.IsArray ? column.ArrayPropertyInformation.ArrayPropertyType : column.PropertyType;

            float minWidth;

            switch (propertyType)
            {
            case SerializedPropertyType.Float:
            case SerializedPropertyType.Integer:
                switch (column.NumericalDisplay)
                {
                case NumericalPropertyDisplay.ReadonlyProgressBar:
                case NumericalPropertyDisplay.ReadonlyProgressBarNormalised:
                    minWidth = 150;
                    break;

                default:
                    minWidth = 50;
                    break;
                }

                break;

            case SerializedPropertyType.Enum:
                switch (column.EnumDisplay)
                {
                case EnumPropertyDisplay.Property:
                case EnumPropertyDisplay.ReadonlyProperty:
                    minWidth = 150;
                    break;

                case EnumPropertyDisplay.ReadonlyLabel:
                    minWidth = 80;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                break;

            case SerializedPropertyType.String:
                minWidth = 150;
                break;

            case SerializedPropertyType.Color:
                minWidth = 150;
                break;

            case SerializedPropertyType.ObjectReference:
                minWidth = 180;
                break;

            case SerializedPropertyType.Generic:
                throw new ArgumentException($"Generic Property Types cannot be accepted by the {nameof(GetMinWidth)} function.");

            case SerializedPropertyType.Boolean:
            case SerializedPropertyType.LayerMask:
            case SerializedPropertyType.Vector2:
            case SerializedPropertyType.Vector3:
            case SerializedPropertyType.Vector4:
            case SerializedPropertyType.Rect:
            case SerializedPropertyType.ArraySize:
            case SerializedPropertyType.Character:
            case SerializedPropertyType.AnimationCurve:
            case SerializedPropertyType.Bounds:
            case SerializedPropertyType.Gradient:
            case SerializedPropertyType.Quaternion:
            case SerializedPropertyType.ExposedReference:
            case SerializedPropertyType.FixedBufferSize:
            case SerializedPropertyType.Vector2Int:
            case SerializedPropertyType.Vector3Int:
            case SerializedPropertyType.RectInt:
            case SerializedPropertyType.BoundsInt:
                                #if UNITY_2019_3_OR_NEWER
            case SerializedPropertyType.ManagedReference:
                                #endif
            default:
                minWidth = 200;
                break;
            }

            return(minWidth);
        }
Example #2
0
        public ColumnContext(AssetListConfiguration.ColumnConfiguration c, int configColumnIndex)
        {
            this.configColumnIndex = configColumnIndex;
            propertyPath           = c.PropertyPath;
            propertyOverride       = PropertyOverride.None;
            if (!c.IsArray)
            {
                ConfigureGUI(c.PropertyType);
                return;
            }

            void ConfigureGUI(SerializedPropertyType propertyType)
            {
                switch (propertyType)
                {
                case SerializedPropertyType.Float:
                case SerializedPropertyType.Integer:
                    switch (c.NumericalDisplay)
                    {
                    case NumericalPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case NumericalPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case NumericalPropertyDisplay.ReadonlyLabel:
                        onGUI = NumericalProperty;
                        break;

                    case NumericalPropertyDisplay.ReadonlyPercentageLabel:
                        onGUI = NumericalPropertyPercentage;
                        break;

                    case NumericalPropertyDisplay.ReadonlyPercentageLabelNormalised:
                        onGUI = NumericalPropertyPercentageNormalised;
                        break;

                    case NumericalPropertyDisplay.ReadonlyProgressBar:
                        onGUI = NumericalPropertyProgressBar;
                        break;

                    case NumericalPropertyDisplay.ReadonlyProgressBarNormalised:
                        onGUI = NumericalPropertyProgressBarNormalised;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.NumericalDisplay), c.NumericalDisplay, null);
                    }

                    break;

                case SerializedPropertyType.Enum:
                    switch (c.EnumDisplay)
                    {
                    case EnumPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case EnumPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case EnumPropertyDisplay.ReadonlyLabel:
                        onGUI = ReadonlyEnumProperty;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.EnumDisplay), c.EnumDisplay, null);
                    }

                    break;

                case SerializedPropertyType.String:
                    switch (c.StringDisplay)
                    {
                    case StringPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case StringPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case StringPropertyDisplay.ReadonlyLabel:
                        onGUI = (rect, sO, property) => GUI.Label(rect, property.stringValue);
                        break;

                    case StringPropertyDisplay.ReadonlyNicifiedLabel:
                        onGUI = (rect, sO, property) => ReadonlyNicifiedLabelProperty(rect, property.stringValue);
                        break;

                    case StringPropertyDisplay.ReadonlyCenteredLabel:
                        onGUI = (rect, sO, property) => ReadonlyCenteredLabelProperty(rect, property.stringValue);
                        break;

                    case StringPropertyDisplay.ReadonlyNicifiedCenteredLabel:
                        onGUI = (rect, sO, property) => ReadonlyNicifiedCenteredLabelProperty(rect, property.stringValue);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.StringDisplay), c.StringDisplay, null);
                    }

                    break;

                case SerializedPropertyType.Color:
                    switch (c.ColorDisplay)
                    {
                    case ColorPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case ColorPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case ColorPropertyDisplay.ReadonlySimplified:
                        onGUI = (rect, sO, property) => ReadonlyColorSimplified(rect, property, false);
                        break;

                    case ColorPropertyDisplay.ReadonlySimplifiedHDR:
                        onGUI = (rect, sO, property) => ReadonlyColorSimplified(rect, property, true);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.ColorDisplay), c.ColorDisplay, null);
                    }

                    break;

                case SerializedPropertyType.ObjectReference:
                    switch (c.ObjectDisplay)
                    {
                    case ObjectPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case ObjectPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case ObjectPropertyDisplay.ReadonlyLabelWithIcon:
                        onGUI = (rect, sO, property) =>
                        {
                            if (property.objectReferenceValue == null)
                            {
                                GUI.Label(rect, "Null");
                            }
                            else
                            {
                                GUI.Label(rect, EditorGUIUtility.ObjectContent(property.objectReferenceValue, null));
                            }
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.ObjectDisplay), c.ObjectDisplay, null);
                    }

                    break;

                case SerializedPropertyType.Generic:
                    throw new NotImplementedException($"{SerializedPropertyType.Generic} is not supported without being an array.");

                case SerializedPropertyType.Boolean:
                case SerializedPropertyType.LayerMask:
                case SerializedPropertyType.Vector2:
                case SerializedPropertyType.Vector3:
                case SerializedPropertyType.Vector4:
                case SerializedPropertyType.Rect:
                case SerializedPropertyType.ArraySize:
                case SerializedPropertyType.Character:
                case SerializedPropertyType.AnimationCurve:
                case SerializedPropertyType.Bounds:
                case SerializedPropertyType.Gradient:
                case SerializedPropertyType.Quaternion:
                case SerializedPropertyType.ExposedReference:
                case SerializedPropertyType.FixedBufferSize:
                case SerializedPropertyType.Vector2Int:
                case SerializedPropertyType.Vector3Int:
                case SerializedPropertyType.RectInt:
                case SerializedPropertyType.BoundsInt:
                                        #if UNITY_2019_3_OR_NEWER
                case SerializedPropertyType.ManagedReference:
                                        #endif
                default:
                    switch (c.DefaultDisplay)
                    {
                    case GUIType.Property:
                        onGUI = Property;
                        break;

                    case GUIType.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    break;
                }
            }

            // Configuration for an array property -------------------------------

            AssetListConfiguration.ArrayData propInfo = c.ArrayPropertyInformation;
            Func <SerializedProperty, SerializedProperty> getProperty = GetArrayPropertyLookup(propInfo);

            getPropertyOverride = context =>
            {
                SerializedProperty property = context.FindProperty(propertyPath);
                return(getProperty.Invoke(property));
            };

            ConfigureGUI(propInfo.ArrayPropertyType);
        }
Example #3
0
        public static string GetString(SerializedProperty property, AssetListConfiguration configuration, AssetListConfiguration.ColumnConfiguration columnConfig)
        {
            switch (property.propertyType)
            {
            case SerializedPropertyType.Float:
                return(GetString(property.floatValue, columnConfig.NumericalDisplay));

            case SerializedPropertyType.Integer:
                return(GetString(property.intValue, columnConfig.NumericalDisplay));

            case SerializedPropertyType.Boolean:
                return(property.boolValue.ToString());

            case SerializedPropertyType.String:
                return(GetString(property.stringValue, columnConfig.StringDisplay));

            case SerializedPropertyType.ObjectReference:
                return(property.objectReferenceValue == null ? string.Empty : property.objectReferenceValue.name);

            case SerializedPropertyType.LayerMask:
                return(property.enumDisplayNames[property.intValue]);

            case SerializedPropertyType.Enum:
                return(property.enumDisplayNames[property.intValue]);

            case SerializedPropertyType.ArraySize:
                return(property.arraySize.ToString());

            case SerializedPropertyType.Character:
                return(property.stringValue);

            case SerializedPropertyType.Color:
                return(property.colorValue.ToString());

            case SerializedPropertyType.Vector2:
                return(property.vector2Value.ToString());

            case SerializedPropertyType.Vector3:
                return(property.vector3Value.ToString());

            case SerializedPropertyType.Vector4:
                return(property.vector4Value.ToString());

            case SerializedPropertyType.Quaternion:
                return(property.quaternionValue.eulerAngles.ToString());

            case SerializedPropertyType.FixedBufferSize:
                return(property.fixedBufferSize.ToString());

            case SerializedPropertyType.Vector2Int:
                return(property.vector2IntValue.ToString());

            case SerializedPropertyType.Vector3Int:
                return(property.vector3IntValue.ToString());

            case SerializedPropertyType.Rect:
                return(property.rectValue.ToString());

            case SerializedPropertyType.RectInt:
                return(property.rectIntValue.ToString());

            case SerializedPropertyType.Bounds:
                return(property.boundsValue.ToString());

            case SerializedPropertyType.BoundsInt:
                return(property.boundsIntValue.ToString());

            case SerializedPropertyType.ExposedReference:
                return(property.exposedReferenceValue.name);

            case SerializedPropertyType.Gradient:
                Gradient gradient = GetGradientValue(property);
                if (gradient == null)
                {
                    return(string.Empty);
                }
                StringBuilder sB                 = new StringBuilder(20);
                string        asciiGradient      = " .:-=+*#%@";
                int           gradientMultiplier = asciiGradient.Length - 1;
                for (int i = 0; i < 20; i++)
                {
                    float grayscale = 1 - gradient.Evaluate(i / 19f).grayscale;
                    sB.Append(asciiGradient[Mathf.Clamp(Mathf.RoundToInt(grayscale * gradientMultiplier), 0, gradientMultiplier)]);
                }
                return(sB.ToString());

            case SerializedPropertyType.AnimationCurve:
                return(property.animationCurveValue.ToString());

                                #if UNITY_2019_3_OR_NEWER
            case SerializedPropertyType.ManagedReference:
                                #endif
            case SerializedPropertyType.Generic:
            default:
                throw new ArgumentOutOfRangeException($"{property.propertyType} is not supported by {nameof(GetString)}");
            }

            Gradient GetGradientValue(SerializedProperty sp)
            {
                PropertyInfo propertyInfo = typeof(SerializedProperty).GetProperty(
                    "gradientValue",
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    typeof(Gradient),
                    Array.Empty <Type>(),
                    null
                    );

                return(propertyInfo?.GetValue(sp, null) as Gradient);
            }
        }