public ColumnContext(AssetListConfiguration c, NamePropertyDisplay nameDisplay, AssetListWindow window) { configColumnIndex = -1; propertyPath = null; propertyOverride = PropertyOverride.Name; Func <SerializedObject, SerializedProperty> getIconProperty = null; if (!string.IsNullOrEmpty(c.IconPropertyPath)) { if (c.IconIsArray) { AssetListConfiguration.ArrayData propInfo = c.IconArrayPropertyInformation; Func <SerializedProperty, SerializedProperty> arrayLookup = GetArrayPropertyLookup(propInfo); if (arrayLookup != null) { getIconProperty = context => { SerializedProperty iconPath = context.FindProperty(c.IconPropertyPath); return(arrayLookup?.Invoke(iconPath)); }; } } else { getIconProperty = context => context.FindProperty(c.IconPropertyPath); } } switch (nameDisplay) { case NamePropertyDisplay.Label: onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, GUI.Label); break; case NamePropertyDisplay.NicifiedLabel: onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyNicifiedLabelProperty); break; case NamePropertyDisplay.CenteredLabel: onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyCenteredLabelProperty); break; case NamePropertyDisplay.NicifiedCenteredLabel: onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyNicifiedCenteredLabelProperty); break; default: throw new ArgumentOutOfRangeException(nameof(nameDisplay), nameDisplay, null); } }
private static Func <SerializedProperty, SerializedProperty> GetArrayPropertyLookup(AssetListConfiguration.ArrayData propInfo) { Func <SerializedProperty, SerializedProperty> getProperty; string arrayPropertyPath = propInfo.ArrayPropertyPath; switch (propInfo.ArrayIndexing) { case ArrayIndexing.First: getProperty = arrayProperty => { if (arrayProperty.arraySize == 0) { return(null); } SerializedProperty element = arrayProperty.GetArrayElementAtIndex(0); return(element?.FindPropertyRelative(arrayPropertyPath)); }; break; case ArrayIndexing.ByKey: Regex regex = new Regex(propInfo.ArrayQuery); string arrayPropertyKey = propInfo.ArrayPropertyKey; getProperty = arrayProperty => { if (arrayProperty == null) { return(null); } for (int i = 0; i < arrayProperty.arraySize; i++) { SerializedProperty property = arrayProperty.GetArrayElementAtIndex(i); SerializedProperty key = property.FindPropertyRelative(arrayPropertyKey); string keyForRegex = AssetListUtility.GetValueForRegex(key); if (!regex.IsMatch(keyForRegex)) { continue; } return(property.FindPropertyRelative(arrayPropertyPath)); } return(null); }; break; case ArrayIndexing.ByIndex: int index = propInfo.ArrayIndex; getProperty = arrayProperty => { if (arrayProperty.arraySize <= index) { return(null); } SerializedProperty element = arrayProperty.GetArrayElementAtIndex(index); return(element?.FindPropertyRelative(arrayPropertyPath)); }; break; default: throw new ArgumentOutOfRangeException(); } return(getProperty); }
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); }