Beispiel #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            QuickReorderableList list = GetList(property, attribute as QuickReorderableAttribute, ARRAY_PROPERTY_NAME);

            if (list != null)
            {
                list.DoList(EditorGUI.IndentedRect(position), label);
            }
            else
            {
                GUI.Label(position, "Array must extend from ReorderableArray", EditorStyles.label);
            }
        }
Beispiel #2
0
        public static QuickReorderableList GetList(SerializedProperty property, QuickReorderableAttribute attrib, int id, string arrayPropertyName)
        {
            if (property == null)
            {
                return(null);
            }

            QuickReorderableList 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;

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

                        list          = new QuickReorderableList(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;

                        //handle surrogate if any

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

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

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

            return(list);
        }
Beispiel #3
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            QuickReorderableList list = GetList(property, attribute as QuickReorderableAttribute, ARRAY_PROPERTY_NAME);

            return(list != null?list.GetHeight() : EditorGUIUtility.singleLineHeight);
        }
Beispiel #4
0
            internal void SetReference(SerializedProperty element, Object objectReference, QuickReorderableList list)
            {
                SerializedProperty prop = !string.IsNullOrEmpty(property) ? element.FindPropertyRelative(property) : null;

                if (prop != null && prop.propertyType == SerializedPropertyType.ObjectReference)
                {
                    prop.objectReferenceValue = objectReference;
                }
            }