Exemple #1
0
        private DragAndDropVisualMode HandleDragDropUpon(DragAndDropData data)
        {
            DragAndDropVisualMode visualMode = DragAndDropVisualMode.Copy;//Move;
            var targetDataBundle             = data.targetNode.bundle as AssetBundleModel.BundleDataInfo;

            if (targetDataBundle != null)
            {
                if (targetDataBundle.IsSceneBundle)
                {
                    visualMode = DragAndDropVisualMode.Rejected;
                }
                else
                {
                    if ((data.hasBundleFolder) || (data.hasScene && !targetDataBundle.IsEmpty()))
                    {
                        return(DragAndDropVisualMode.Rejected);
                    }
                    else
                    {
                        if (data.args.performDrop)
                        {
                            if (data.draggedNodes != null)
                            {
                                AssetBundleModel.Model.HandleBundleMerge(data.draggedNodes, targetDataBundle);
                                ReloadAndSelect(targetDataBundle.NameHashCode, false);
                            }
                            else if (data.paths != null)
                            {
                                AssetBundleModel.Model.MoveAssetToBundle(data.paths, targetDataBundle.m_name.BundleName, targetDataBundle.m_name.Variant);
                                AssetBundleModel.Model.ExecuteAssetMove();
                                ReloadAndSelect(targetDataBundle.NameHashCode, false);
                            }
                        }
                    }
                }
            }
            else
            {
                var folder = data.targetNode.bundle as AssetBundleModel.BundleFolderConcreteInfo;
                if (folder != null)
                {
                    if (data.args.performDrop)
                    {
                        if (data.draggedNodes != null)
                        {
                            AssetBundleModel.Model.HandleBundleReparent(data.draggedNodes, folder);
                            Reload();
                        }
                        else if (data.paths != null)
                        {
                            DragPathsToNewSpace(data.paths, folder, data.hasScene);
                        }
                    }
                }
                else
                {
                    visualMode = DragAndDropVisualMode.Rejected; //must be a variantfolder
                }
            }
            return(visualMode);
        }
Exemple #2
0
 /// <summary>Creates a drag area using a vertical layout,
 /// and returns TRUE if the drag conditions were met.</summary>
 public static bool DragAndDropArea(Type allowedObjectsType, DragAndDropVisualMode visualMode, GUIStyle guiStyle, Action blockAction, params GUILayoutOption[] options)
 {
     bool allowDragAndDrop = true;
     if (Event.current.type == EventType.DragUpdated) {
         UnityEngine.Object[] draggedObjs = DragAndDrop.objectReferences;
         if (draggedObjs.Length == 0) allowDragAndDrop = false;
         int objsCount = draggedObjs.Length;
         for (int i = 0; i < objsCount; ++i) {
             if (draggedObjs[i].GetType() != allowedObjectsType) {
                 allowDragAndDrop = false;
                 break;
             }
         }
     }
     return DragAndDropArea(allowDragAndDrop, visualMode, guiStyle, blockAction, options);
 }
Exemple #3
0
 /// <summary>
 /// Creates a drag area using a vertical layout,
 /// and returns TRUE when a drag is concluded (meaning something was released on the area) 
 /// and drag conditions were met.
 /// </summary>
 public static bool DragAndDropArea(bool allowDragAndDrop, DragAndDropVisualMode visualMode, GUIStyle guiStyle, Action blockAction, params GUILayoutOption[] options)
 {
     _Vertical(guiStyle, GUI.backgroundColor, blockAction, options);
     if (allowDragAndDrop && Event.current.type == EventType.DragUpdated && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) {
         DragAndDrop.visualMode = visualMode;
     } else if (Event.current.type == EventType.DragPerform && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) {
         return true;
     }
     return false;
 }
Exemple #4
0
 /// <summary>Creates a drag area using a vertical layout,
 /// and returns TRUE if the drag conditions were met.</summary>
 public static bool DragAndDropArea(Type allowedObjectsType, DragAndDropVisualMode visualMode, Action blockAction, params GUILayoutOption[] options)
 { return DragAndDropArea(allowedObjectsType, visualMode, null, blockAction, options); }
Exemple #5
0
        // ===================================================================================
        // SPECIAL LAYOUT METHODS ------------------------------------------------------------

        /// <summary>Creates a drag area using a vertical layout,
        /// and returns TRUE if the drag conditions were met.</summary>
        public static bool DragAndDropArea(bool allowDragAndDrop, DragAndDropVisualMode visualMode, Action blockAction, params GUILayoutOption[] options)
        { return DragAndDropArea(allowDragAndDrop, visualMode, null, blockAction, options); }
Exemple #6
0
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, bool firstItem)
        {
            if (targetItem == null)
            {
                if (m_DropData != null)
                {
                    m_DropData.dropTargetControlID = 0;
                    m_DropData.rowMarkerControlID  = 0;
                }

                bool perform = Event.current.type == EventType.DragPerform;
                DragAndDrop.visualMode = DoDrag(null, null, perform, DropPosition.Below);
                Debug.LogError(DoDrag(null, null, perform, DropPosition.Below));
                if (DragAndDrop.visualMode != DragAndDropVisualMode.None && perform)
                {
                    FinalizeDragPerformed(true);
                }
                return(false);
            }

            Vector2 mousePosition     = Event.current.mousePosition;
            bool    flag              = m_TreeView.data.CanBeParent(targetItem);
            Rect    rect              = targetItemRect;
            float   betweenHalfHeight = !flag ? targetItemRect.height * 0.5f : m_TreeView.gui.halfDropBetweenHeight;

            if (firstItem)
            {
                rect.yMin -= betweenHalfHeight;
            }
            rect.yMax += betweenHalfHeight;

            if (!rect.Contains(mousePosition))
            {
                return(false);
            }

            DropPosition          dropPosition       = mousePosition.y < targetItemRect.yMax - betweenHalfHeight ? (!firstItem || mousePosition.y > targetItemRect.yMin + betweenHalfHeight ? (!flag ? DropPosition.Above : DropPosition.Upon) : DropPosition.Above) : DropPosition.Below;
            TreeViewItem          parentItem         = !m_TreeView.data.IsExpanded(targetItem) || !targetItem.hasChildren ? targetItem.parent : targetItem;
            DragAndDropVisualMode andDropVisualMode1 = DragAndDropVisualMode.None;

            if (Event.current.type == EventType.DragPerform)
            {
                if (dropPosition == DropPosition.Upon)
                {
                    andDropVisualMode1 = DoDrag(targetItem, targetItem, true, dropPosition);
                }

                if (andDropVisualMode1 == DragAndDropVisualMode.None && parentItem != null)
                {
                    andDropVisualMode1 = DoDrag(parentItem, targetItem, true, dropPosition);
                }

                if (andDropVisualMode1 != DragAndDropVisualMode.None)
                {
                    FinalizeDragPerformed(false);
                }
                else
                {
                    DragCleanup(true);
                    m_TreeView.NotifyListenersThatDragEnded(null, false);
                }
            }
            else
            {
                if (m_DropData == null)
                {
                    m_DropData = new DropData();
                }
                m_DropData.dropTargetControlID = 0;
                m_DropData.rowMarkerControlID  = 0;
                int itemControlId = TreeView.GetItemControlID(targetItem, m_TreeView);
                HandleAutoExpansion(itemControlId, targetItem, targetItemRect, betweenHalfHeight, mousePosition);

                if (dropPosition == DropPosition.Upon)
                {
                    andDropVisualMode1 = DoDrag(targetItem, targetItem, false, dropPosition);
                }

                if (andDropVisualMode1 != DragAndDropVisualMode.None)
                {
                    m_DropData.dropTargetControlID = itemControlId;
                    DragAndDrop.visualMode         = andDropVisualMode1;
                }
                else if (parentItem != null)
                {
                    DragAndDropVisualMode andDropVisualMode2 = DoDrag(parentItem, targetItem, false, dropPosition);
                    if (andDropVisualMode2 != DragAndDropVisualMode.None)
                    {
                        drawRowMarkerAbove             = dropPosition == DropPosition.Above;
                        m_DropData.rowMarkerControlID  = itemControlId;
                        m_DropData.dropTargetControlID = !drawRowMarkerAbove?TreeView.GetItemControlID(parentItem, m_TreeView) : 0;

                        DragAndDrop.visualMode = andDropVisualMode2;
                    }
                }
            }
            Event.current.Use();
            return(true);
        }
Exemple #7
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       = 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));
        }
Exemple #8
0
        // This method is called from TreeView and handles:
        // - Where the dragged items are dropped (above, below or upon)
        // - Auto expansion of collapsed items when hovering over them
        // - Setting up the render markers for drop location (horizontal lines)
        // 'targetItem' is null when not hovering over any target Item, if so the rest of the arguments are invalid
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, int row)
        {
            bool perform = Event.current.type == EventType.DragPerform;

            // Are we dragging outside any items
            if (targetItem == null)
            {
                // If so clear any drop markers
                if (m_DropData != null)
                {
                    m_DropData.dropTargetControlID = 0;
                    m_DropData.rowMarkerControlID  = 0;
                }

                // And let client decide what happens when dragging outside items

                DragAndDrop.visualMode = DoDrag(null, null, perform, DropPosition.Below);
                if (DragAndDrop.visualMode != DragAndDropVisualMode.None && perform)
                {
                    FinalizeDragPerformed(true);
                }

                return(false);
            }

            DropPosition dropPosition;

            if (!TryGetDropPosition(targetItem, targetItemRect, row, out dropPosition))
            {
                return(false);
            }

            TreeViewItem parentItem = null;

            switch (dropPosition)
            {
            case DropPosition.Upon:
            {
                // Client must decide what happens when dropping upon: e.g: insert last or first in child list
                parentItem = targetItem;
            }
            break;

            case DropPosition.Below:
            {
                // When hovering between an expanded parent and its first child then make sure we change state to match that
                if (m_TreeView.data.IsExpanded(targetItem) && targetItem.hasChildren)
                {
                    parentItem   = targetItem;
                    targetItem   = targetItem.children[0];
                    dropPosition = DropPosition.Above;
                }
                else
                {
                    // Drop as next sibling to target
                    parentItem = targetItem.parent;
                }
            }
            break;

            case DropPosition.Above:
            {
                parentItem = targetItem.parent;
            }
            break;

            default:
                Assert.IsTrue(false, "Unhandled enum");
                break;
            }


            DragAndDropVisualMode mode = DragAndDropVisualMode.None;

            if (perform)
            {
                // Try Drop on top of element
                if (dropPosition == DropPosition.Upon)
                {
                    mode = DoDrag(targetItem, targetItem, true, dropPosition);
                }

                // Fall back to dropping on parent  (drop between elements)
                if (mode == DragAndDropVisualMode.None && parentItem != null)
                {
                    mode = DoDrag(parentItem, targetItem, true, dropPosition);
                }

                // Finalize drop
                if (mode != DragAndDropVisualMode.None)
                {
                    FinalizeDragPerformed(false);
                }
                else
                {
                    DragCleanup(true);
                    m_TreeView.NotifyListenersThatDragEnded(null, false);
                }
            }
            else // DragUpdate
            {
                if (m_DropData == null)
                {
                    m_DropData = new DropData();
                }
                m_DropData.dropTargetControlID = 0;
                m_DropData.rowMarkerControlID  = 0;

                int itemControlID = TreeViewController.GetItemControlID(targetItem);
                HandleAutoExpansion(itemControlID, targetItem, targetItemRect);

                // Try drop on top of element
                if (dropPosition == DropPosition.Upon)
                {
                    mode = DoDrag(targetItem, targetItem, false, dropPosition);
                }

                if (mode != DragAndDropVisualMode.None)
                {
                    m_DropData.dropTargetControlID = itemControlID;
                    DragAndDrop.visualMode         = mode;
                }
                // Fall back to dropping on parent (drop between elements)
                else if (targetItem != null && parentItem != null)
                {
                    mode = DoDrag(parentItem, targetItem, false, dropPosition);

                    if (mode != DragAndDropVisualMode.None)
                    {
                        drawRowMarkerAbove            = dropPosition == DropPosition.Above;
                        m_DropData.rowMarkerControlID = itemControlID;
                        DragAndDrop.visualMode        = mode;
                    }
                }
            }

            Event.current.Use();
            return(true);
        }