void DrawChildren(Rect listRect, Rect headerRect, Rect sizeRect, Rect visibleRect, EventType previousEvent)
        {
            if (Event.current.type == EventType.Used && sizeRect.Contains(Event.current.mousePosition))
            {
                Event.current.type = previousEvent;
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.DefaultPropertyField(sizeRect, m_ArraySize, GUIContent.none);
            EditorGUI.LabelField(sizeRect, new GUIContent("", "Array Size"));
            if (EditorGUI.EndChangeCheck())
            {
                m_ReorderableList.InvalidateCache();
            }

            if (headerRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
                {
                    Object[] objReferences = DragAndDrop.objectReferences;
                    foreach (var o in objReferences)
                    {
                        Object validatedObject = EditorGUI.ValidateObjectFieldAssignment(new[] { o }, typeof(Object), m_ReorderableList.serializedProperty, EditorGUI.ObjectFieldValidatorOptions.None);
                        if (validatedObject != null)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        }
                        else
                        {
                            continue;
                        }

                        if (Event.current.type == EventType.DragPerform)
                        {
                            ReorderableList.defaultBehaviours.DoAddButton(m_ReorderableList, validatedObject);
                        }
                    }
                    DragAndDrop.AcceptDrag();
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.None;
                Event.current.Use();
            }

            if (Property.isExpanded)
            {
                listRect.y      += m_HeaderHeight + Constants.kHeaderPadding;
                listRect.height -= m_HeaderHeight + Constants.kHeaderPadding;

                visibleRect.y -= listRect.y;
                m_ReorderableList.DoList(listRect, visibleRect);
            }
        }
Beispiel #2
0
        public void Draw(Rect r, Rect visibleArea)
        {
            var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();

            m_IsNotInPrefabContextModeWithOverrides = prefabStage == null || prefabStage.mode != PrefabStage.Mode.InContext || !PrefabStage.s_PatchAllOverriddenProperties ||
                                                      Selection.objects.All(obj => PrefabUtility.IsPartOfAnyPrefab(obj) && !AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(obj)).Equals(AssetDatabase.AssetPathToGUID(prefabStage.assetPath)));
            m_ReorderableList.draggable = m_Reorderable && m_IsNotInPrefabContextModeWithOverrides;

            Rect headerRect = new Rect(r.x, r.y, r.width, m_HeaderHeight);
            Rect sizeRect   = new Rect(headerRect.xMax - Constants.kArraySizeWidth, headerRect.y,
                                       Constants.kArraySizeWidth, m_HeaderHeight);

            EventType prevType = Event.current.type;

            if (Event.current.type == EventType.MouseUp && sizeRect.Contains(Event.current.mousePosition))
            {
                Event.current.type = EventType.Used;
            }

            EditorGUI.BeginChangeCheck();
            m_Foldout = EditorGUI.BeginFoldoutHeaderGroup(headerRect, m_Foldout, m_Header);
            EditorGUI.EndFoldoutHeaderGroup();
            if (EditorGUI.EndChangeCheck())
            {
                m_ReorderableList.ClearCacheRecursive();
            }

            if (Event.current.type == EventType.Used && sizeRect.Contains(Event.current.mousePosition))
            {
                Event.current.type = prevType;
            }

            EditorGUI.DefaultPropertyField(sizeRect, m_ArraySize, GUIContent.none);
            EditorGUI.LabelField(sizeRect, new GUIContent("", "Array Size"));

            if (headerRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
                {
                    Object[] objReferences = DragAndDrop.objectReferences;
                    foreach (var o in objReferences)
                    {
                        if (EditorGUI.ValidateObjectFieldAssignment(new[] { o }, typeof(Object), m_ReorderableList.serializedProperty,
                                                                    EditorGUI.ObjectFieldValidatorOptions.None) != null)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        }
                        else
                        {
                            continue;
                        }

                        if (Event.current.type == EventType.DragPerform)
                        {
                            ReorderableList.defaultBehaviours.DoAddButton(m_ReorderableList, o);
                        }
                    }
                    DragAndDrop.AcceptDrag();
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.None;
                Event.current.Use();
            }

            if (m_Foldout)
            {
                r.y      += m_HeaderHeight + Constants.kHeaderPadding;
                r.height -= m_HeaderHeight + Constants.kHeaderPadding;

                visibleArea.y -= r.y;
                m_ReorderableList.DoList(r, visibleArea);
            }
        }