Exemplo n.º 1
0
        void HandleNativeDragDropInBottomArea(Editor[] editors, Rect rect)
        {
            if (!DraggingOverRect(rect))
            {
                return;
            }

            Editor editor = InspectorWindowUtils.GetFirstNonImportInspectorEditor(editors);

            if (editor == null)
            {
                return;
            }

            DragAndDrop.visualMode = DragAndDrop.Drop(DragAndDropWindowTarget.inspector, 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 = DragAndDrop.Drop(DragAndDropWindowTarget.inspector, new[] { settingsEditor.target }, Event.current.type == EventType.DragPerform);
                        if (Event.current.type == EventType.DragPerform)
                        {
                            DragAndDrop.AcceptDrag();
                        }
                    }
                }
            }

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

            return(DragAndDrop.Drop(DragAndDropWindowTarget.projectBrowser, dragToInstanceId, AssetDatabase.GetAssetPath(dragToInstanceId), perform));
        }
Exemplo n.º 4
0
        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       = HierarchyDropFlags.None;
            var searchActive = !string.IsNullOrEmpty(dataSource.searchString);

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

                if (parentForDraggedObjectsOutsideItems != null)
                {
                    // Use specific parent for DragAndDropForwarding
                    return(DragAndDrop.Drop(DragAndDropWindowTarget.hierarchy, 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 |= HierarchyDropFlags.DropUpon;
                    return(DragAndDrop.Drop(DragAndDropWindowTarget.hierarchy, 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 |= HierarchyDropFlags.DropUpon;
            }
            else
            {
                if (dropPos == TreeViewDragging.DropPosition.Above)
                {
                    option |= HierarchyDropFlags.DropAbove;
                }

                option |= HierarchyDropFlags.DropBetween;
            }

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

            if (isDroppingBetweenParentAndFirstChild)
            {
                option |= HierarchyDropFlags.DropAfterParent;
            }

            int gameObjectOrSceneInstanceID = GetDropTargetInstanceID(hierarchyTargetItem, dropPos);

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

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

            return(DragAndDrop.Drop(DragAndDropWindowTarget.hierarchy, gameObjectOrSceneInstanceID, option, null, perform));
        }