コード例 #1
0
            public void AddProperty(SerializedProperty property)
            {
                // Check if this property actually belongs to the same direct child
                if (GetGrandParentPath(property).Equals(Parent) == false)
                    return;

                ReorderableList propList = new ReorderableList(
                    property.serializedObject, property,
                    draggable: true, displayHeader: false,
                    displayAddButton: true, displayRemoveButton: true)
                {
                    headerHeight = 5
                };

                propList.drawElementCallback = delegate(Rect rect, int index, bool active, bool focused)
                {
                    SerializedProperty targetElement = property.GetArrayElementAtIndex(index);
                    bool isExpanded = targetElement.isExpanded;
                    rect.height = EditorGUI.GetPropertyHeight(targetElement, GUIContent.none, isExpanded);

                    if (targetElement.hasVisibleChildren)
                        rect.xMin += 10;

                    // Get Unity to handle drawing each element
                    EditorGUI.PropertyField(rect, targetElement, isExpanded);

                    // Height might have changed when dealing with serialized class
                    // Call the select callback when height changes to reset the list elementHeight
                    float newHeight = EditorGUI.GetPropertyHeight(targetElement, GUIContent.none, targetElement.isExpanded);
                    if (rect.height != newHeight)
                    {
                        propList.onSelectCallback(propList);
                #if UNITY_5_1 || UNITY_5_2
                        propList.elementHeight = Mathf.Max(propList.elementHeight, newHeight);
                #endif
                    }
                };

                propList.onSelectCallback = delegate(ReorderableList list)
                {
                    SerializedProperty targetElement = property.GetArrayElementAtIndex(list.index);
                    list.elementHeight = EditorGUI.GetPropertyHeight(targetElement, GUIContent.none, targetElement.isExpanded);
                };

                propList.onChangedCallback = delegate(ReorderableList list)
                {
                    list.onSelectCallback(list);
                };

                // Unity 5.3 onwards allows reorderable lists to have variable element heights
                #if UNITY_5_3_OR_NEWER
                propList.elementHeightCallback = delegate(int index)
                {
                    SerializedProperty arrayElement = property.GetArrayElementAtIndex(index);
                    return EditorGUI.GetPropertyHeight(arrayElement, GUIContent.none, arrayElement.isExpanded);
                };
                #endif
                propList.onAddCallback = delegate(ReorderableList list)
                {
                    list.serializedProperty.arraySize++;
                    propList.onSelectCallback(list);
                };

                propIndex.Add(property.propertyPath, propList);
            }