Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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;
                    }
                };
            }
        }