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.DropOnHierarchyWindow(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.DropOnHierarchyWindow(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.DropOnHierarchyWindow(gameObjectOrSceneInstanceID, option, null, perform)); }