Esempio n. 1
0
        private static void OnMouseMove(MouseMoveEvent evt)
        {
            if (evt.target is IDraggable draggable && draggable.DragState == DragState.Ready)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = draggable.DragObjects;
                DragAndDrop.SetGenericData(_dragData, draggable.DragData);
                DragAndDrop.StartDrag(draggable.DragText);

                draggable.DragState = DragState.Dragging;
            }
        }
Esempio n. 2
0
            internal static void HandleDragAndDrop(int instanceId, Rect selectionRect)
            {
                // HACK: Uses EditorApplication.hierarchyWindowItemOnGUI.
                // Only works when there is at least one item in the scene.
                var  current         = UnityEngine.Event.current;
                var  eventType       = current.type;
                bool isDraggingEvent = eventType == EventType.DragUpdated;
                bool isDropEvent     = eventType == EventType.DragPerform;

                if (isDraggingEvent || isDropEvent)
                {
                    var mouseOverWindow = EditorWindow.mouseOverWindow;
                    if (mouseOverWindow != null)
                    {
                        // One, existing, valid SkeletonDataAsset
                        var references = UnityEditor.DragAndDrop.objectReferences;
                        if (references.Length == 1)
                        {
                            var skeletonDataAsset = references[0] as SkeletonDataAsset;
                            if (skeletonDataAsset != null && skeletonDataAsset.GetSkeletonData(true) != null)
                            {
                                // Allow drag-and-dropping anywhere in the Hierarchy Window.
                                // HACK: string-compare because we can't get its type via reflection.
                                const string HierarchyWindow     = "UnityEditor.SceneHierarchyWindow";
                                const string GenericDataTargetID = "target";
                                if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal))
                                {
                                    if (isDraggingEvent)
                                    {
                                        UnityEditor.DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                                        var mouseOverTarget = UnityEditor.EditorUtility.InstanceIDToObject(instanceId);
                                        if (mouseOverTarget)
                                        {
                                            DragAndDrop.SetGenericData(GenericDataTargetID, mouseOverTarget);
                                        }
                                        // note: do not use the current event, otherwise we lose the nice mouse-over highlighting.
                                    }
                                    else if (isDropEvent)
                                    {
                                        var       parentGameObject = DragAndDrop.GetGenericData(GenericDataTargetID) as UnityEngine.GameObject;
                                        Transform parent           = parentGameObject != null ? parentGameObject.transform : null;
                                        DragAndDropInstantiation.ShowInstantiateContextMenu(skeletonDataAsset, Vector3.zero, parent);
                                        UnityEditor.DragAndDrop.AcceptDrag();
                                        current.Use();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
Esempio n. 3
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();
            string[] paths = FindRows(args.draggedItemIDs)
                             .Cast <BundleAssetTreeViewItem>()
                             .Select(x => x.path)
                             .ToArray();

            DragAndDrop.paths = paths;
            DragAndDrop.SetGenericData(INSIDE_DRAG_KEY, true);
            DragAndDrop.StartDrag("move");
        }
Esempio n. 4
0
 protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
 {
     Debug.LogFormat("Id's: \n {0}", args.draggedItemIDs);
     if (DragAndDrop.objectReferences != null && DragAndDrop.objectReferences.Length > 0)
     {
         DragAndDrop.SetGenericData(k_ObjectDragID, DragAndDrop.objectReferences);
     }
     else
     {
         base.SetupDragAndDrop(args);
     }
 }
Esempio n. 5
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            PrefabsListElement itemClicked = treeModel.Find(args.draggedItemIDs[0]);

            if (itemClicked.rustID != 0)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.SetGenericData(prefabName, itemClicked);
                DragAndDrop.StartDrag("Spawn Prefab");
                PrefabManager.PrefabToSpawn = PrefabManager.Load(itemClicked.rustID);
            }
        }
        public virtual void StartDrag(int draggedItemId, List <int> selectedItemIdList)
        {
            if (GenericDragId == null)
            {
                throw new NullReferenceException("You must specify a unique string for GenericDragId");
            }

            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData(GenericDragId, GetItemList(selectedItemIdList));
            DragAndDrop.objectReferences = new UnityEngine.Object[0];
            DragAndDrop.StartDrag(selectedItemIdList.Count + " item" + (selectedItemIdList.Count <= 1 ? string.Empty : "s"));
        }
 protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
 {
     if (GetController().CanDrag() && !hasSearch)
     {
         DragAndDrop.PrepareStartDrag();
         var draggedRows = GetRows().Where(item => args.draggedItemIDs.Contains(item.id)).ToList();
         DragAndDrop.SetGenericData(k_GenericDragID, draggedRows);
         DragAndDrop.objectReferences = new UnityEngine.Object[] {};   // this IS required for dragging to work
         string title = draggedRows.Count == 1 ? draggedRows[0].displayName : "< Multiple >";
         DragAndDrop.StartDrag(title);
     }
 }
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();
            var selectedBundles = new List <AssetBundleState.BundleInfo.TreeItem>();

            foreach (var i in args.draggedItemIDs.Select(b => Utilities.FindItem <AssetBundleState.BundleInfo.TreeItem>(rootItem, b)))
            {
                GatherAllNodes(i, selectedBundles);
            }
            DragAndDrop.SetGenericData("AssetBundleState.BundleInfo.TreeItem", selectedBundles);
            DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            DragAndDrop.StartDrag("AssetBundleTree");
        }
Esempio n. 9
0
            private void    StartDrag(Rect r, Row row)
            {
                DragAndDrop.PrepareStartDrag();

                for (int i = 0; i < this.notes.Count; i++)
                {
                    if (this.notes[i].row == row)
                    {
                        DragAndDrop.SetGenericData("n", this.notes[i]);
                        break;
                    }
                }
            }
Esempio n. 10
0
    private void PrepareDrag(EditorControl list)
    {
        ListViewCtrl list2 = list as ListViewCtrl;

        if (null == list)
        {
            return;
        }

        DragAndDrop.PrepareStartDrag();
        DragAndDrop.objectReferences = new Object[] { null };   // 必须在这里初始化objectReferences,否则会遇到Unity drag & drop的bug
        DragAndDrop.SetGenericData("CustomDragFromList", list2.SelectItems);
    }
Esempio n. 11
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();
            bool isMultiDrag = args.draggedItemIDs.Count > 1;

            if (isMultiDrag)
            {
            }
            else
            {
                DragAndDrop.SetGenericData("MissionEditor_Drag", SortItemIDsInRowOrder(args.draggedItemIDs)[0]);
            }
            DragAndDrop.StartDrag("MissionEditor");
        }
Esempio n. 12
0
        public override void DrawItem(Rect position, int index)
        {
            LudiqGUI.Inspector(metadata[index], position, GUIContent.none);

            var item = this[index];

            var controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                // Exclude delete button from draggable position
                var draggablePosition = ReorderableListGUI.CurrentItemTotalPosition;
                draggablePosition.xMax = position.xMax + 2;

                if (Event.current.button == (int)MouseButton.Left && draggablePosition.Contains(Event.current.mousePosition))
                {
                    selectedList = this;
                    selectedItem = item;

                    if (alwaysDragAndDrop || Event.current.alt)
                    {
                        GUIUtility.hotControl  = controlID;
                        mouseDragStartPosition = Event.current.mousePosition;
                        Event.current.Use();
                    }
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;

                    if (Vector2.Distance(mouseDragStartPosition, Event.current.mousePosition) >= MouseDragThreshold)
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new UnityObject[0];
                        DragAndDrop.paths            = new string[0];
                        DragAndDrop.SetGenericData(DraggedListItem.TypeName, new DraggedListItem(this, index, item));
                        DragAndDrop.StartDrag(metadata.path);
                    }

                    Event.current.Use();
                }

                break;
            }
        }
Esempio n. 13
0
        public override void    OnGUI()
        {
            if (this.button == null)
            {
                this.button = new GUIStyle(GUI.skin.button);
            }

            float w = this.button.CalcSize(this.content).x;

            if (this.image == null)
            {
                this.button.padding.left = GUI.skin.button.padding.left;
            }
            else
            {
                this.button.padding.left = (int)this.hub.height;
                w += 12F;                 // Remove texture width, because Button calculates using the whole height.
            }

            Rect r = GUILayoutUtility.GetRect(w, this.hub.height, GUI.skin.button);

            if (Event.current.type == EventType.MouseDrag &&
                Utility.position2D != Vector2.zero &&
                DragAndDrop.GetGenericData(Utility.DragObjectDataName) != null &&
                (Utility.position2D - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance)
            {
                Utility.position2D = Vector2.zero;
                DragAndDrop.StartDrag("Drag Object");
                Event.current.Use();
            }
            else if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition) == true)
            {
                NGEditorGUILayout.PingObject(asset);

                Utility.position2D = Event.current.mousePosition;
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = new Object[] { this.asset };
                DragAndDrop.SetGenericData(Utility.DragObjectDataName, 1);
            }

            GUI.Button(r, this.content, this.button);
            if (this.image != null)
            {
                r       = GUILayoutUtility.GetLastRect();
                r.x    += 4F;
                r.width = r.height;
                GUI.DrawTexture(r, this.image);
            }
        }
Esempio n. 14
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();

            if (args.draggedItemIDs.Count > 0)
            {
                var item = FindItem(args.draggedItemIDs[0], rootItem) as GraphCollectionTreeItem;
                DragAndDrop.SetGenericData("GraphCollectionTree.DraggedItem", item);
            }

            DragAndDrop.paths            = null;
            DragAndDrop.objectReferences = m_EmptyObjectList.ToArray();
            DragAndDrop.visualMode       = DragAndDropVisualMode.Move;
            DragAndDrop.StartDrag("GraphCollectionTree");
        }
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            if (hasSearch)
            {
                return;
            }
            DragAndDrop.PrepareStartDrag();
            var draggedRows = GetRows().Where(item => args.draggedItemIDs.Contains(item.id)).ToList();

            DragAndDrop.SetGenericData(GENERIC_DRAG_ID, draggedRows);
            DragAndDrop.objectReferences = new Object[] { }; // this IS required for dragging to work
            var title = draggedRows.Count == 1 ? draggedRows[0].displayName : "< Multiple >";

            DragAndDrop.StartDrag(title);
        }
        /// <summary>
        /// Creates the DragAndDrop object's references, and begins the drag operation.
        /// </summary>
        /// <param name="forgelightGame">The forgelight game containing "actor"</param>
        /// <param name="actor">The selected actor</param>
        private void BeginDrag(ForgelightGame forgelightGame, Adr actor)
        {
            ActorDefinition actorDefinition = new ActorDefinition
            {
                forgelightGame  = forgelightGame,
                actorDefinition = actor
            };

            DragAndDrop.objectReferences = new Object[0];
            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData("ActorDefinition", actorDefinition);
            DragAndDrop.StartDrag("ActorDrag");

            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
        }
Esempio n. 17
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            if (this.hasSearch)
            {
                return;
            }

            DragAndDrop.PrepareStartDrag();
            List <TreeViewItem> draggedRows = this.GetRows().Where(item => args.draggedItemIDs.Contains(item.id)).ToList();

            DragAndDrop.SetGenericData(genericDragId, draggedRows);
            DragAndDrop.objectReferences = new UnityEngine.Object[] { };             // this IS required for dragging to work
            string title = draggedRows.Count == 1 ? draggedRows[0].displayName : "< Multiple >";

            DragAndDrop.StartDrag(title);
        }
Esempio n. 18
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            if (hasSearch)
            {
                return;
            }

            DragAndDrop.PrepareStartDrag();
            var draggedRows = GetRows().Where(item => args.draggedItemIDs.Contains(item.id)).ToList();

            DragAndDrop.SetGenericData(k_GenericDragID, draggedRows);
            DragAndDrop.objectReferences = new UnityEngine.Object[] { };
            string title = draggedRows[0].displayName;

            DragAndDrop.StartDrag(title);
        }
Esempio n. 19
0
        private void StartDrag()
        {
            var ele = currentClickedElement;

            if (ele != null)
            {
                DragAndDrop.activeControlID = ele.GetHashCode();
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.SetGenericData("uNode", ele);
                DragAndDrop.StartDrag("Dragging Element");
                if (ele is IDragableElement)
                {
                    (ele as IDragableElement).StartDrag();
                }
            }
        }
Esempio n. 20
0
        private void StartDrag()
        {
            TreeViewItem tree = currentClickedTree;

            if (tree != null)
            {
                tree.UnregisterCallback <MouseMoveEvent>(OnMouseMove);
                if (tree is IDragableTree)
                {
                    DragAndDrop.activeControlID = tree.GetHashCode();
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.SetGenericData("uNode", tree);
                    DragAndDrop.StartDrag("Dragging Trees");
                }
            }
        }
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();

            var selectedNodes = new List<AssetEntryTreeViewItem>();
            foreach (var id in args.draggedItemIDs)
            {
                var item = FindItemInVisibleRows(id);
                selectedNodes.Add(item);
            }
            DragAndDrop.paths = null;
            DragAndDrop.objectReferences = new Object[] { };
            DragAndDrop.SetGenericData("AssetEntryTreeViewItem", selectedNodes);
            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            DragAndDrop.StartDrag("AssetBundleTree");
        }
Esempio n. 22
0
        private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            plyVar   plyVar   = this.variables.varDefs[index];
            plyVarEd plyVarEd = plyVariablesEditor.editors[plyVar.ValueHandler.GetType()];

            plyVariablesEditor.GC_VarName.text = plyVar.name;
            plyVariablesEditor.GC_VarType.text = plyVarEd.VarTypeName(plyVar);
            float num   = (float)(plyEdGUI.Styles.Label_RT.CalcSize(plyVariablesEditor.GC_VarType).x + 7.0);
            Rect  rect2 = rect;

            rect2.height = EditorGUIUtility.singleLineHeight;
            rect2.y     += 3f;
            rect2.width -= num;
            GUI.Label(rect2, plyVariablesEditor.GC_VarName, EditorStyles.boldLabel);
            rect2.x     = (float)(rect2.xMax + 5.0);
            rect2.width = num;
            GUI.Label(rect2, plyVariablesEditor.GC_VarType);
            rect2.y    += (float)(rect2.height + 2.0);
            rect2.x     = (float)(rect.x + 20.0);
            rect2.width = (float)(rect.width - 20.0);
            EditorGUI.BeginChangeCheck();
            if (plyVarEd.DrawEditor(rect2, this.isOnSceneObject, plyVar, plyVar, 0))
            {
                this.advVar = plyVar;
                this.advEd  = plyVarEd;
                plyEdGUI.ClearFocus();
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.Save();
            }
            if (Event.current.type == EventType.MouseDrag && rect.Contains(Event.current.mousePosition))
            {
                plyEdGUI.ClearFocus();
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = new UnityEngine.Object[0];
                DragAndDrop.paths            = null;
                DragAndDrop.SetGenericData("plyVariable", new DragDropData
                {
                    name       = plyVar.name,
                    plyVarType = this.varsType,
                    varValType = plyVar.variableType
                });
                DragAndDrop.StartDrag(plyVar.name);
                Event.current.Use();
            }
        }
Esempio n. 23
0
    void PrepareDragDrop(object sender, System.EventArgs args)
    {
        TreeViewItem item = (TreeViewItem)sender;

        try
        {
            if (item == null || !item.IsDraggable)
            {
                return;
            }

            UnityEngine.Object[] objectReferences = new UnityEngine.Object[1];
            AkTreeInfo           treeInfo         = (AkTreeInfo)item.DataContext;

            AkDragDropData DDData = null;

            string objType = GetObjectType(treeInfo.ObjectType);
            if (objType == "State" || objType == "Switch")
            {
                AkDragDropGroupData DDGroupData    = new AkDragDropGroupData();
                AkTreeInfo          ParentTreeInfo = (AkTreeInfo)item.Parent.DataContext;
                DDGroupData.groupGuid = new Guid(ParentTreeInfo.Guid);
                DDGroupData.groupID   = ParentTreeInfo.ID;
                DDData = DDGroupData;
            }
            else
            {
                DDData = new AkDragDropData();
            }

            DDData.name     = item.Header;
            DDData.guid     = new Guid(treeInfo.Guid);
            DDData.ID       = treeInfo.ID;
            DDData.typeName = objType;

            objectReferences[0]          = DragDropHelperMonoScript;
            GUIUtility.hotControl        = 0;
            DragAndDrop.objectReferences = objectReferences;
            DragAndDrop.SetGenericData(AkDragDropHelper.DragDropIdentifier, DDData);
            DragAndDrop.StartDrag("Dragging an AkObject");
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
Esempio n. 24
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();

            var selectedBundles = new List <AssetBundleModel.BundleInfo>();

            foreach (var id in args.draggedItemIDs)
            {
                var item = FindItem(id, rootItem) as AssetBundleModel.BundleTreeItem;
                selectedBundles.Add(item.bundle);
            }
            DragAndDrop.paths            = null;
            DragAndDrop.objectReferences = m_EmptyObjectList.ToArray();
            DragAndDrop.SetGenericData("AssetBundleModel.BundleInfo", selectedBundles);
            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;//Move;
            DragAndDrop.StartDrag("AssetBundleTree");
        }
Esempio n. 25
0
    protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
    {
        base.SetupDragAndDrop(args);

        m_DraggedItem.Clear();
        foreach (var itm in args.draggedItemIDs)
        {
            m_DraggedItem.Add(FindItem(itm, rootItem) as PackTreeItem);
        }

        DragAndDrop.objectReferences = new UnityEngine.Object[0];
        DragAndDrop.PrepareStartDrag();
        DragAndDrop.SetGenericData(ROW_DRAG_OP, "");
        DragAndDrop.StartDrag("Tree view Item");

        IsDragging = true;
    }
        public void StartDrag(StartDragArgs args)
        {
            DragAndDrop.PrepareStartDrag();

            if (args.unityObjectReferences != null)
            {
                DragAndDrop.objectReferences = args.unityObjectReferences.ToArray();
            }

            DragAndDrop.SetGenericData(k_UserDataKey, args.userData);
            foreach (DictionaryEntry entry in args.genericData)
            {
                DragAndDrop.SetGenericData((string)entry.Key, entry.Value);
            }

            DragAndDrop.StartDrag(args.title);
        }
Esempio n. 27
0
        private bool HandleDragging()
        {
            Rect scrolledArea = _area;

            scrolledArea.y += ScrollPosition.y;

            if (Event.current.ClickedWithin(scrolledArea, clickPos) && clickedWithin && Event.current.type != EventType.Used && Event.current.button == 0 && Event.current.mousePosition.y < maxY + 2)
            {
                dragStart  = clickPos;
                wantToDrag = true;
            }

            if (wantToDrag && Event.current.type != EventType.Used && (Event.current.type != EventType.DragUpdated || Event.current.type != EventType.DragPerform) && Event.current.type == EventType.MouseDrag && Vector2.Distance(dragStart, Event.current.mousePosition) > 10.0f)
            {
                wantToDrag = false;
                if (draggingNode != null)
                {
                    DragAndDrop.PrepareStartDrag();
                    //GUIUtility.hotControl = GUIDCreator.Create();
                    DragAndDrop.SetGenericData(draggingNode.GetName, draggingNode);
                    DragAndDrop.paths            = null;
                    DragAndDrop.objectReferences = new UnityEngine.Object[] { draggingNode };
                    DragAndDrop.StartDrag("InAudio Tree Drag N Drop");
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                DragAndDrop.PrepareStartDrag();
            }

            bool canDropObjects = false;

            if (CanDropObjects != null)
            {
                canDropObjects = CanDropObjects(HoverOver, DragAndDrop.objectReferences);
            }
            if (canDropObjects)
            {
                DrawBackground(HoverOverArea);
                IsDirty = true;
            }
            return(canDropObjects);
        }
 public void InitializeDrag(IList <int> indices)
 {
     if (CanDrag(indices))
     {
         // TODO: convert indices to items
         DragAndDrop.PrepareStartDrag();
         DragAndDrop.SetGenericData(DataIdentifier, indices);
         DragAndDrop.paths = new string[] { PathIdentifier };
         if (indices.Count == 1)
         {
             DragAndDrop.StartDrag("1 item");
         }
         else
         {
             DragAndDrop.StartDrag(indices.Count + " items");
         }
     }
 }
Esempio n. 29
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            if (args.draggedItemIDs.Count == 0)
            {
                return;
            }

            StringTreeViewItem item = FindItem(args.draggedItemIDs[0], rootItem) as StringTreeViewItem;

            if (item == null || item.JsonType == JsonType.NotJson)
            {
                return;
            }

            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData(typeof(StringTreeViewItem).FullName, item);
            DragAndDrop.StartDrag(item.Label + item.StringValue);
        }
        void StartDrag()
        {
            // DragAndDrop.StartDrag prints an error if the current event is not a drag
            var eventType = Event.current.type;

            if (!(eventType == EventType.MouseDown || eventType == EventType.MouseDrag))
            {
                return;
            }

            DragAndDrop.PrepareStartDrag();

            // ReSharper disable once CoVariantArrayConversion
            DragAndDrop.objectReferences = new [] { BackingObject };
            DragAndDrop.SetGenericData(DragDataTitle, this);
            DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            DragAndDrop.StartDrag(k_DragTitle);
        }