예제 #1
0
        void HandleNativeDragDropInBottomArea(Editor[] editors, Rect rect)
        {
            if (!DraggingOverRect(rect))
            {
                return;
            }

            Editor editor = InspectorWindowUtils.GetFirstNonImportInspectorEditor(editors);

            if (editor == null)
            {
                return;
            }

            DragAndDrop.visualMode = DragAndDropService.Drop(DragAndDropService.kInspectorDropDstId, editor.targets, Event.current.type == EventType.DragPerform);

            if (Event.current.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();
                m_TargetIndex = -1;
                GUIUtility.ExitGUI();
            }
        }
        public override void OnGUI(string searchContext)
        {
            if (settingsEditor != null)
            {
                using (new EditorGUI.DisabledScope(!settingsEditor.IsEnabled()))
                {
                    using (new SettingsWindow.GUIScope())
                        settingsEditor.OnInspectorGUI();

                    // Emulate the Inspector by handling DnD at the native level.
                    var remainingRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true));
                    if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform) && remainingRect.Contains(Event.current.mousePosition))
                    {
                        DragAndDrop.visualMode = DragAndDropService.Drop(DragAndDropService.kInspectorDropDstId, new[] { settingsEditor.target }, Event.current.type == EventType.DragPerform);
                        if (Event.current.type == EventType.DragPerform)
                        {
                            DragAndDrop.AcceptDrag();
                        }
                    }
                }
            }

            base.OnGUI(searchContext);
        }
        public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos)
        {
            var dragToInstanceId = parentItem?.id ?? 0;

            return(DragAndDropService.Drop(DragAndDropService.kProjectBrowserDropDstId, dragToInstanceId, AssetDatabase.GetAssetPath(dragToInstanceId), perform));
        }
        public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos)
        {
            var hierarchyTargetItem = targetItem as GameObjectTreeViewItem;

            // Allow client to handle drag
            if (m_CustomDragHandling != null)
            {
                DragAndDropVisualMode dragResult = m_CustomDragHandling(parentItem as GameObjectTreeViewItem, hierarchyTargetItem, dropPos, perform);
                if (dragResult != DragAndDropVisualMode.None)
                {
                    return(dragResult);
                }
            }

            // Scene dragging logic
            DragAndDropVisualMode dragSceneResult = DoDragScenes(parentItem as GameObjectTreeViewItem, hierarchyTargetItem, perform, dropPos);

            if (dragSceneResult != DragAndDropVisualMode.None)
            {
                return(dragSceneResult);
            }

            if (targetItem != null && !IsDropTargetUserModifiable(hierarchyTargetItem, dropPos))
            {
                return(DragAndDropVisualMode.Rejected);
            }

            var option       = InternalEditorUtility.HierarchyDropMode.kHierarchyDragNormal;
            var searchActive = !string.IsNullOrEmpty(dataSource.searchString);

            if (searchActive)
            {
                option |= InternalEditorUtility.HierarchyDropMode.kHierarchySearchActive;
            }
            if (parentItem == null || targetItem == null)
            {
                // Here we are dragging outside any treeview items:

                if (parentForDraggedObjectsOutsideItems != null)
                {
                    // Use specific parent for DragAndDropForwarding
                    return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, 0, option, parentForDraggedObjectsOutsideItems, perform));
                }
                else
                {
                    // Simulate drag upon the last loaded scene in the hierarchy (adds as last root sibling of the last scene)
                    Scene lastScene = dataSource.GetLastScene();
                    if (!lastScene.IsValid())
                    {
                        return(DragAndDropVisualMode.Rejected);
                    }

                    option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropUpon;
                    return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, lastScene.handle, option, null, perform));
                }
            }

            // Here we are hovering over items

            var draggingUpon = dropPos == TreeViewDragging.DropPosition.Upon;

            if (searchActive && !draggingUpon)
            {
                return(DragAndDropVisualMode.None);
            }

            if (draggingUpon)
            {
                option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropUpon;
            }
            else
            {
                if (dropPos == TreeViewDragging.DropPosition.Above)
                {
                    option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropAbove;
                }
                else
                {
                    option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropBetween;
                }
            }

            bool isDroppingBetweenParentAndFirstChild = parentItem != null && targetItem != parentItem && dropPos == DropPosition.Above && parentItem.children[0] == targetItem;

            if (isDroppingBetweenParentAndFirstChild)
            {
                option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropAfterParent;
            }

            int gameObjectOrSceneInstanceID = GetDropTargetInstanceID(hierarchyTargetItem, dropPos);

            if (gameObjectOrSceneInstanceID == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (perform && SubSceneGUI.IsUsingSubScenes() && !IsValidSubSceneDropTarget(gameObjectOrSceneInstanceID, dropPos, DragAndDrop.objectReferences))
            {
                return(DragAndDropVisualMode.Rejected);
            }

            return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, gameObjectOrSceneInstanceID, option, null, perform));
        }