public ReorderableListOfStructures( ReorderableListAttribute attribute, SerializedProperty property, Type listType, Type elementType) : base(attribute, property, listType, elementType) { }
//---------------------------------------------------------------------- public ReorderableListOfValues( ReorderableListAttribute attribute, SerializedProperty primaryProperty, Type listType, Type elementType) : base( serializedObject: primaryProperty.serializedObject, elements: primaryProperty.Copy(), draggable: !attribute.disableDragging, displayHeader: true, displayAddButton: !attribute.disableAdding, displayRemoveButton: !attribute.disableRemoving) { this.listType = listType; this.elementType = elementType; this.elementHeaderFormat = attribute.elementHeaderFormat; this.showFooterButtons = (displayAdd || displayRemove) && !attribute.hideFooterButtons; this.singularListHeaderFormat = attribute.SingularListHeaderFormat ?? "{0} ({1})"; this.pluralListHeaderFormat = attribute.PluralListHeaderFormat ?? "{0} ({1})"; this.backgroundColor = new Color( attribute.r, attribute.g, attribute.b); this.serializedProperties = AcquireSerializedProperties( this.serializedProperty, attribute.parallelListNames); this.parallelListLayout = attribute.parallelListLayout; headerHeight -= 2; drawHeaderCallback = DrawHeaderCallback; drawFooterCallback = DrawFooterCallback; elementHeightCallback = ElementHeightCallback; drawElementCallback = DrawElementCallback; drawElementBackgroundCallback = DrawElementBackgroundCallback; onAddCallback = OnAddCallback; onCanRemoveCallback = OnCanRemoveCallback; onRemoveCallback = OnRemoveCallback; onSelectCallback = OnSelectCallback; onReorderCallback = OnReorderCallback; #if UNITY_2018_1_OR_NEWER drawNoneElementCallback = DrawEmptyElementCallback; #endif // UNITY_2018_1_OR_NEWER }
protected ReorderableListOfValues GetReorderableList( ReorderableListAttribute attribute, FieldInfo fieldInfo, SerializedProperty property) { string propertyPath = property.propertyPath; if (this.m_MostRecentReorderableList != null) { if (this.m_MostRecentPropertyPath == propertyPath) { this.m_MostRecentReorderableList.serializedProperty = property; return(this.m_MostRecentReorderableList); } } this.m_MostRecentReorderableList = this.m_ReorderableListMap .Find(propertyPath); if (this.m_MostRecentReorderableList == null) { ReorderableListOfValues reorderableList = CreateReorderableList( attribute, fieldInfo, property); this.m_ReorderableListMap.Add(propertyPath, reorderableList); this.m_MostRecentReorderableList = reorderableList; } else { this.m_MostRecentReorderableList.serializedProperty = property; } this.m_MostRecentPropertyPath = propertyPath; return(this.m_MostRecentReorderableList); }
//---------------------------------------------------------------------- public ReorderableListOfSubassets( ReorderableListAttribute attribute, SerializedProperty property, Type listType, Type elementType, Type[] subassetTypes) : base(attribute, property, listType, elementType) { m_SubassetTypes = subassetTypes; m_UseFullSubassetTypeNames = SubassetTypeNamesAreAmbiguous(); onCanAddCallback = OnCanAddCallback; if (hasSingleSubassetType) { onAddCallback = OnAddCallback; } else if (hasMultipleSubassetTypes) { onAddDropdownCallback = OnAddDropdownCallback; } }
CreateReorderableList( ReorderableListAttribute attribute, FieldInfo fieldInfo, SerializedProperty property) { Type listType = fieldInfo.FieldType; Type elementType = GetArrayOrListElementType(listType); bool elementIsValue = elementType.IsEnum || elementType.IsPrimitive || elementType == typeof(string) || elementType == typeof(Color) || elementType == typeof(LayerMask) || elementType == typeof(Vector2) || elementType == typeof(Vector3) || elementType == typeof(Vector4) || elementType == typeof(Rect) || elementType == typeof(AnimationCurve) || elementType == typeof(Bounds) || elementType == typeof(Gradient) || elementType == typeof(Quaternion) || elementType == typeof(Vector2Int) || elementType == typeof(Vector3Int) || elementType == typeof(RectInt) || elementType == typeof(BoundsInt); if (elementIsValue) { return (new ReorderableListOfValues( attribute, property, listType, elementType )); } bool elementIsUnityEngineObject = typeof(UnityEngine.Object) .IsAssignableFrom(elementType); if (elementIsUnityEngineObject) { bool elementsAreSubassets = elementIsUnityEngineObject && attribute != null && attribute.elementsAreSubassets; if (elementsAreSubassets) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); IEnumerable <Type> types = assemblies.SelectMany(a => a.GetTypes()); Type[] subassetTypes = types.Where(t => t.IsAbstract == false && t.IsGenericTypeDefinition == false && elementType.IsAssignableFrom(t) ) .ToArray(); return (new ReorderableListOfSubassets( attribute, property, listType, elementType, subassetTypes )); } else { return (new ReorderableListOfValues( attribute, property, listType, elementType )); } } Type elementPropertyDrawerType = GetDrawerTypeForType(elementType); if (elementPropertyDrawerType == null) { bool elementIsStruct = elementType.IsValueType && elementType.IsEnum == false && elementType.IsPrimitive == false; bool elementIsClass = elementType.IsClass; if (elementIsStruct || elementIsClass) { return (new ReorderableListOfStructures( attribute, property, listType, elementType )); } } return (new ReorderableListOfValues( attribute, property, listType, elementType )); }