コード例 #1
0
        private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, SerializedProperty property, ReorderableListData data)
        {
            data.HeaderCallback = rect =>
            {
                return(DoHeader(property, rect, reorderableAttr.DisplayName));
            };

            data.HeaderMenuCallback = (genericMenu) =>
            {
                return(DoHeaderMenu(property, genericMenu));
            };

            if (!string.IsNullOrEmpty(reorderableAttr.ElementName))
            {
                data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i);
            }
            else if (reorderableAttr.ElementName == null)
            {
                data.ElementNameCallback = i => null;
            }

            data.ElementHeaderCallback = (position, label, inspectableObject) =>
            {
                return(DoElementHeader(position, label, inspectableObject));
            };

            data.ElementFooterCallback = (position, inspectableObject) =>
            {
                DoElementFooter(position, inspectableObject);
            };

            data.IsDrawObjectReference = reorderableAttr.IsDrawObjectReference;
        }
コード例 #2
0
        //
        // -- PRIVATE --
        //

        private ReorderableList GetList(SerializedProperty property)
        {
            SerializedProperty array;
            SerializedProperty id;

            ReorderableList list = null;

            if (IsValid(property, out array, out id))
            {
                ReorderableAttribute attrib = attribute as ReorderableAttribute;

                if (attrib != null)
                {
                    if (!lists.TryGetValue(id.intValue, out list))
                    {
                        list = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, ReorderableList.ElementDisplayType.Auto, attrib.elementNameProperty, GetIcon(attrib.elementIconPath));
                        lists.Add(list.id, list);

                        id.intValue = list.id;
                    }
                    else
                    {
                        list.List = array;
                    }
                }
            }

            return(list);
        }
コード例 #3
0
        public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, int id)
        {
            if (property == null)
            {
                return(null);
            }

            ReorderableList    list  = null;
            SerializedProperty array = property.FindPropertyRelative("array");

            if (array != null && array.isArray)
            {
                if (!lists.TryGetValue(id, out list))
                {
                    if (attrib != null)
                    {
                        Texture icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null;

                        list = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, ReorderableList.ElementDisplayType.Auto, attrib.elementNameProperty, attrib.elementNameOverride, icon);
                    }
                    else
                    {
                        list = new ReorderableList(array, true, true, true);
                    }

                    lists.Add(id, list);
                }
                else
                {
                    list.List = array;
                }
            }

            return(list);
        }
コード例 #4
0
        private void HandleReorderableOptions(ReorderableAttribute arrayAttr, SerializedProperty property, SortableListData data)
        {
            // Custom element header
            if (string.IsNullOrEmpty(arrayAttr.ElementHeader) == false)
            {
                data.ElementHeaderCallback = i => string.Format("{0} {1}", arrayAttr.ElementHeader, (arrayAttr.HeaderZeroIndex ? i : i + 1));
            }

            // Draw property as single line
            if (arrayAttr.ElementSingleLine)
            {
                var list = data.GetPropertyList(property);
                list.elementHeightCallback = index => EditorGUIUtility.singleLineHeight;
                list.drawElementCallback   = (rect, index, active, focused) =>
                {
                    var element    = property.GetArrayElementAtIndex(index);
                    int childCount = element.Copy().CountRemaining();
                    childCount -= (property.arraySize - 1) - index;

                    if (element.NextVisible(true))
                    {
                        float restoreWidth = EditorGUIUtility.labelWidth;
                        EditorGUIUtility.labelWidth /= childCount;

                        float padding = 5f;
                        float width   = rect.width - padding * (childCount - 1);
                        width /= childCount;

                        Rect childRect = new Rect(rect)
                        {
                            width = width
                        };
                        int depth = element.Copy().depth;
                        do
                        {
                            if (element.depth != depth)
                            {
                                break;
                            }
                            if (childCount <= 2)
                            {
                                EditorGUI.PropertyField(childRect, element, false);
                            }
                            else
                            {
                                EditorGUI.PropertyField(childRect, element, GUIContent.none, false);
                            }
                            childRect.x += width + padding;
                        } while (element.NextVisible(false));

                        EditorGUIUtility.labelWidth = restoreWidth;
                    }
                };
            }
        }
コード例 #5
0
        private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, SerializedProperty property, ReorderableListData data)
        {
            data.HeaderCallback = rect =>
            {
                return(DoHeader(property, rect, reorderableAttr.DisplayName));
            };

            if (!string.IsNullOrEmpty(reorderableAttr.ElementName))
            {
                data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i);
            }
        }
コード例 #6
0
        public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, int id, string arrayPropertyName)
        {
            if (property == null)
            {
                return(null);
            }

            ReorderableList    list  = null;
            SerializedProperty array = property.FindPropertyRelative(arrayPropertyName);

            if (array != null && array.isArray)
            {
                if (!lists.TryGetValue(id, out list))
                {
                    if (attrib != null)
                    {
                        Texture icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null;

                        ReorderableList.ElementDisplayType displayType = attrib.singleLine ? ReorderableList.ElementDisplayType.SingleLine : ReorderableList.ElementDisplayType.Auto;

                        list               = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon);
                        list.paginate      = attrib.paginate;
                        list.pageSize      = attrib.pageSize;
                        list.sortable      = attrib.sortable;
                        list.elementLabels = attrib.labels;

                        //handle surrogate if any

                        if (attrib.surrogateType != null)
                        {
                            SurrogateCallback callback = new SurrogateCallback(attrib.surrogateProperty);

                            list.surrogate = new ReorderableList.Surrogate(attrib.surrogateType, callback.SetReference);
                        }
                    }
                    else
                    {
                        list = new ReorderableList(array, true, true, true);
                    }

                    lists.Add(id, list);
                }
                else
                {
                    list.List = array;
                }
            }

            return(list);
        }
コード例 #7
0
        private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, InspectableProperty property, ReorderableListData data)
        {
            data.HeaderCallback = rect =>
            {
                return(DoHeader(property, rect, reorderableAttr.DisplayName));
            };

            if (!string.IsNullOrEmpty(reorderableAttr.ElementName))
            {
                data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i);
            }
            else if (reorderableAttr.ElementName == null)
            {
                data.ElementNameCallback = i => null;
            }

            data.IsDrawObjectReference = reorderableAttr.IsDrawObjectReference;
        }
コード例 #8
0
        private void CreateListData(SerializedProperty property)
        {
            string parent = GetGrandParentPath(property);

            // Try to find the grand parent in SortableListData
            SortableListData data = listIndex.Find(listData => listData.Parent.Equals(parent));

            if (data == null)
            {
                data = new SortableListData(parent);
                listIndex.Add(data);
            }

            data.AddProperty(property);
            object[] attr = property.GetAttributes <ReorderableAttribute>();
            if (attr != null && attr.Length == 1)
            {
                ReorderableAttribute arrayAttr = (ReorderableAttribute)attr[0];
                if (arrayAttr != null)
                {
                    HandleReorderableOptions(arrayAttr, property, data);
                }
            }
        }
コード例 #9
0
        protected virtual ReorderableList GetReorderableList(SerializedProperty listProperty)
        {
            if (_list == null)
            {
                _list = new ReorderableList(listProperty.serializedObject, listProperty, true, true, true, true);
                _list.drawHeaderCallback += delegate(Rect rect)
                {
                    ReorderableAttribute selecterAttribute = attribute as ReorderableAttribute;
                    string title = listProperty.displayName;
                    if (selecterAttribute != null)
                    {
                        title = selecterAttribute.title;
                    }
                    EditorGUI.LabelField(rect, title);
                };

                _list.drawElementCallback = delegate(Rect rect, int index, bool isActive, bool isFocused)
                {
                    EditorGUI.PropertyField(rect, listProperty.GetArrayElementAtIndex(index), true);
                };
            }

            return(_list);
        }
コード例 #10
0
 public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, string arrayPropertyName)
 {
     return(GetList(property, attrib, GetListId(property), arrayPropertyName));
 }
コード例 #11
0
 public SerializedField(object declaringObject, SerializedProperty serializedProperty, MemberInfo memberInfo) : base(declaringObject, serializedProperty, memberInfo)
 {
     this.m_fieldInfo          = memberInfo as FieldInfo;
     this.m_fieldType          = m_fieldInfo.FieldType;
     this.m_reordableAttribute = ReflectionUtils.GetAttribute <ReorderableAttribute>(m_fieldInfo);
 }
コード例 #12
0
            public static ReorderableCollection GetDrawableCollection(SerializedProperty property,
                                                                      ReorderableAttribute attrib = null, int id = -1, string backingListName = DefaultBackingListName)
            {
                //
                if (property == null)
                {
                    return(null);
                }

                if (id == -1)
                {
                    id = GetListId(property);
                }

                if (attrib == null)
                {
                    attrib = new ReorderableAttribute();
                }


                ReorderableCollection collection = null;
                var backingList = property.FindPropertyRelative(backingListName);

                var obj = GetTargetObjectOfProperty(property);

                if (backingList == null || !backingList.isArray || !(obj is BaseReorderableCollection))
                {
                    return(null);
                }

                if (!Lists.TryGetValue(id, out collection))
                {
                    var icon = !string.IsNullOrEmpty(attrib.elementIconPath)
                        ? AssetDatabase.GetCachedIcon(attrib.elementIconPath)
                        : null;

                    var displayType = attrib.singleLine
                        ? ReorderableCollection.ElementDisplayType.SingleLine
                        : ReorderableCollection.ElementDisplayType.Auto;

                    collection = new ReorderableCollection(backingList, attrib.add, attrib.remove, attrib.draggable,
                                                           displayType,
                                                           attrib.elementNameProperty, attrib.elementNameOverride, icon)
                    {
                        Paginate = attrib.paginate, PageSize = attrib.pageSize, sortable = attrib.sortable
                    };

                    // handle surrogate if any
                    if (attrib.surrogateType != null)
                    {
                        var callback = new SurrogateCallback(attrib.surrogateProperty);
                        collection.surrogate =
                            new ReorderableCollection.Surrogate(attrib.surrogateType, callback.SetReference);
                    }

                    Lists.Add(id, collection);
                }
                else
                {
                    collection.List = backingList;
                }

                return(collection);
            }
コード例 #13
0
 public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib)
 {
     return(GetList(property, attrib, GetListId(property)));
 }
コード例 #14
0
        private void HandleReorderableOptions(ReorderableAttribute arrayAttr, SerializedProperty property, SortableListData data)
        {
            // Custom element header
            if (string.IsNullOrEmpty(arrayAttr.ElementHeader) == false)
            {
                data.ElementHeaderCallback = i => string.Format("{0} {1}", arrayAttr.ElementHeader, (arrayAttr.HeaderZeroIndex ? i : i + 1));
            }

            // Draw property as single line
            if (arrayAttr.ElementSingleLine)
            {
                var list = data.GetPropertyList(property);
#if UNITY_5_3_OR_NEWER
                list.elementHeightCallback         = index => EditorGUIUtility.singleLineHeight + 6;
                list.drawElementBackgroundCallback = (rect, index, active, focused) =>
                {
                    if (focused == false)
                    {
                        return;
                    }
                    if (styleHighlight == null)
                    {
                        styleHighlight = GUI.skin.FindStyle("MeTransitionSelectHead");
                    }
                    GUI.Box(rect, GUIContent.none, styleHighlight);
                };
#endif

                list.drawElementCallback = (rect, index, active, focused) =>
                {
                    var element = property.GetArrayElementAtIndex(index);
                    element.isExpanded = false;

                    int childCount = data.GetElementCount(property);
                    if (childCount < 1)
                    {
                        return;
                    }

                    rect.y      += 3;
                    rect.height -= 6;

                    if (element.NextVisible(true))
                    {
                        float restoreWidth = EditorGUIUtility.labelWidth;
                        EditorGUIUtility.labelWidth /= childCount;

                        float padding = 5f;
                        float width   = rect.width - padding * (childCount - 1);
                        width /= childCount;

                        Rect childRect = new Rect(rect)
                        {
                            width = width
                        };
                        int depth = element.Copy().depth;
                        do
                        {
                            if (element.depth != depth)
                            {
                                break;
                            }

                            if (childCount <= 2)
                            {
                                EditorGUI.PropertyField(childRect, element, false);
                            }
                            else
                            {
                                EditorGUI.PropertyField(childRect, element, GUIContent.none, false);
                            }
                            childRect.x += width + padding;
                        } while (element.NextVisible(false));

                        EditorGUIUtility.labelWidth = restoreWidth;
                    }
                };
            }
        }
コード例 #15
0
        public static Pair <bool, ReorderableList> GetList(SerializedProperty property, ReorderableAttribute attrib, int id)
        {
            if (property == null)
            {
                return(new Pair <bool, ReorderableList>(false, null));
            }

            ReorderableList    list  = null;
            SerializedProperty array = property.isArray ? property : property.FindPropertyRelative("array");

            bool justCreated = false;

            if (array != null && array.isArray)
            {
                if (!lists.TryGetValue(id, out list))
                {
                    if (attrib != null)
                    {
                        Texture icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null;

                        ReorderableList.ElementDisplayType displayType = attrib.singleLine ? ReorderableList.ElementDisplayType.SingleLine : ReorderableList.ElementDisplayType.Auto;

                        list          = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon);
                        list.paginate = attrib.paginate;
                        list.pageSize = attrib.pageSize;
                    }
                    else
                    {
                        list = new ReorderableList(array, true, true, true);
                    }

                    justCreated = true;
                    lists.Add(id, list);
                }
                else
                {
                    list.List = array;
                }
            }

            return(PairUtils.MakePair(justCreated, list));
        }
コード例 #16
0
 public ReorderAttributeDrawer(ReorderableAttribute attribute)
 {
 }