Exemplo n.º 1
0
 internal static void StartDrag(UnityEngine.Object obj, string label = null)
 {
     s_LastDraggedObject = obj;
     if (!s_LastDraggedObject)
     {
         return;
     }
     DragAndDrop.PrepareStartDrag();
     DragAndDrop.objectReferences = new[] { s_LastDraggedObject };
     DragAndDrop.StartDrag(label ?? s_LastDraggedObject.name);
 }
Exemplo n.º 2
0
 internal static void StartDrag(UnityEngine.Object[] objects, string label = null)
 {
     s_LastDraggedObjects = objects;
     if (s_LastDraggedObjects == null)
     {
         return;
     }
     DragAndDrop.PrepareStartDrag();
     DragAndDrop.objectReferences = s_LastDraggedObjects;
     DragAndDrop.StartDrag(label);
 }
Exemplo n.º 3
0
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();
            DragAndDrop.objectReferences = m_EmptyObjectList.ToArray();
            List <AssetBundleModel.AssetTreeItem> items =
                new List <AssetBundleModel.AssetTreeItem>(args.draggedItemIDs.Select(id => FindItem(id, rootItem) as AssetBundleModel.AssetTreeItem));

            DragAndDrop.paths = items.Select(a => a.asset.fullAssetName).ToArray();
            DragAndDrop.SetGenericData("AssetListTreeSource", this);
            DragAndDrop.StartDrag("AssetListTree");
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
 public static void StartDrag(UnityEngine.Object[] objects, string[] paths, string label = null)
 {
     s_LastDraggedObjects = objects;
     if (paths == null || paths.Length == 0)
     {
         return;
     }
     DragAndDrop.PrepareStartDrag();
     DragAndDrop.objectReferences = s_LastDraggedObjects;
     DragAndDrop.paths            = paths;
     DragAndDrop.StartDrag(label);
 }
Exemplo n.º 6
0
 private void StartDrag()
 {
     if (!_selectedPrefab)
     {
         return;
     }
     DragAndDrop.PrepareStartDrag();
     DragAndDrop.paths            = new[] { AssetDatabase.GetAssetPath(_selectedPrefab) };
     DragAndDrop.objectReferences = new[] { _selectedPrefab };
     DragAndDrop.StartDrag(_selectedPrefab.ToString());
     _mouseDownTime = EditorApplication.timeSinceStartup;
 }
    protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
    {
        base.SetupDragAndDrop(args);

        m_Dragged.Clear();
        m_Dragged.AddRange(args.draggedItemIDs);

        DragAndDrop.objectReferences = new Object[0];
        DragAndDrop.PrepareStartDrag();
        DragAndDrop.StartDrag("Item view");
        //DragAndDrop.visualMode = DragAndDropVisualMode.Move;
    }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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");
        }
Exemplo n.º 10
0
        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"));
        }
Exemplo n.º 11
0
 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);
     }
 }
Exemplo n.º 12
0
        private static void HandleDragEvent(Object currentObject)
        {
#if !UNITY_EDITOR_OSX
            DragAndDrop.PrepareStartDrag();
            DragAndDrop.StartDrag(currentObject.name);
            DragAndDrop.objectReferences = new Object[] { currentObject };
            if (EditorUtility.IsPersistent(currentObject))
            {
                DragAndDrop.paths = new string[] { AssetDatabase.GetAssetPath(currentObject) };
            }
            Event.current.Use();
#endif
        }
Exemplo n.º 13
0
        private void OnElementDrag(ISearchableElement elem)
        {
            if (!elem.SupportDrag || elem.DragObject == null)
            {
                return;
            }

            DragAndDrop.PrepareStartDrag();
            DragAndDrop.objectReferences = new[] { elem.DragObject };
            DragAndDrop.StartDrag("Dragging Object");

            isDragging_ = true;
        }
Exemplo n.º 14
0
        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");
        }
 private void EndDrag(UnityEngine.Object o)
 {
     if (Event.current.type == EventType.MouseDrag)
     {
         if (lastRect.Contains(Event.current.mousePosition))
         {
             DragAndDrop.PrepareStartDrag();
             DragAndDrop.objectReferences = new UnityEngine.Object[] { o };
             DragAndDrop.StartDrag(string.Format("Dragging {0}", o.ToString()));
             Event.current.Use();
         }
     }
 }
Exemplo n.º 16
0
 public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
 {
     DragAndDrop.PrepareStartDrag();
     // DragAndDrop.objectReferences = ProjectWindowUtil.GetDragAndDropObjects(draggedItem.id, draggedItemIDs);
     // DragAndDrop.paths = ProjectWindowUtil.GetDragAndDropPaths(draggedItem.id, draggedItemIDs);
     if (DragAndDrop.objectReferences.Length > 1)
     {
         DragAndDrop.StartDrag("<Multiple>");
     }
     else
     {
         DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(InternalEditorUtility.GetObjectFromInstanceID(draggedItem.id)));
     }
 }
Exemplo n.º 17
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;
            }
        }
Exemplo n.º 18
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");
        }
Exemplo n.º 19
0
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("<<", GUILayout.Width(50.0f)))
        {
            _Prev();
        }
        if (GUILayout.Button("...", GUILayout.Width(50.0f)))
        {
            m_PopupWindow = new HistoryWindow(this);
            PopupWindow.Show(histRect, m_PopupWindow);
        }
        if (Event.current.type == EventType.Repaint)
        {
            histRect = GUILayoutUtility.GetLastRect();
        }
        if (GUILayout.Button(">>", GUILayout.Width(50.0f)))
        {
            _Next();
        }

        // Ping + drag done as label as drag seems to not work with buttons?
        GUILayout.Label("\u2299", GUILayout.Width(20.0f));
        var rect     = GUILayoutUtility.GetLastRect();
        var cev      = Event.current;
        var mousePos = cev.mousePosition;
        var o        = Selection.activeObject;

        if (rect.Contains(mousePos) && o != null)
        {
            var mouseStartDrag = false;
            var mouseClick     = false;
            mouseStartDrag = (cev.type == EventType.MouseDrag) && cev.button == 0;
            mouseClick     = (cev.type == EventType.MouseUp) && cev.button == 0 && cev.clickCount == 1;
            if (mouseStartDrag)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.StartDrag(o.name);
                DragAndDrop.objectReferences = new UnityEngine.Object[] { o };
                Event.current.Use();
            }
            else if (mouseClick)
            {
                EditorGUIUtility.PingObject(o);
                Event.current.Use();
            }
        }

        EditorGUILayout.EndHorizontal();
    }
Exemplo n.º 20
0
        void showClassifiedSprite(Sprite sprite, float fWidth, bool bImgOnly)
        {
            var             evt = Event.current;
            GUILayoutOption wOption = GUILayout.Width(fWidth), hOption = GUILayout.Height(bImgOnly ? fWidth : (fWidth - 2 * EditorGUIUtility.singleLineHeight));

            using (new EditorGUILayout.VerticalScope(wOption))
            {
                Rect ImgRT = EditorGUILayout.GetControlRect(wOption, hOption);

                if (SelectedSprites.Contains(sprite))
                {
                    EditorGUI.DrawRect(ImgRT, Color.gray);
                }

                CustomEditorGUI.DrawSprite(ImgRT, sprite, Color.clear, true, true);

                if (!bImgOnly)
                {
                    EditorGUILayout.ObjectField(sprite, typeof(Sprite), allowSceneObjects: false, options: wOption);
                    if (SpriteAtlasDic.ContainsKey(sprite))
                    {
                        AtlasField(SpriteAtlasDic[sprite], false);
                    }
                }

                if (ImgRT.Contains(evt.mousePosition))
                {
                    if (evt.type == EventType.MouseUp || evt.type == EventType.MouseDrag)
                    {
                        if (!SelectedSprites.Contains(sprite))
                        {
                            SelectedSprites.Add(sprite);
                        }
                        else if (evt.type == EventType.MouseUp)
                        {
                            SelectedSprites.Remove(sprite);
                        }

                        if (evt.type == EventType.MouseDrag)
                        {
                            DragAndDrop.PrepareStartDrag();
                            DragAndDrop.objectReferences = SelectedSprites.ToArray();
                            DragAndDrop.StartDrag("Dragging title");
                        }
                        Event.current.Use();
                    }
                }
            }
        }
Exemplo n.º 21
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);
            }
        }
        protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
        {
            DragAndDrop.PrepareStartDrag();

            var ids   = SortItemIDsInRowOrder(args.draggedItemIDs);
            var items = new List <UnityEngine.Object>(ids.Count);

            items.AddRange(ids.Select(EditorUtility.InstanceIDToObject).Where(obj => obj != null));

            DragAndDrop.objectReferences = items.ToArray();

            var title = items.Count > 1 ? "<Multiple>" : items[0].name;

            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;
        }
Exemplo n.º 24
0
        private void OnPointerMoveEvent(PointerMoveEvent evt)
        {
            var movingDistance = (_mouseOffset - evt.localPosition).magnitude;

            if (_dragState == DragState.Ready && evt.pressedButtons == 1 && movingDistance > 25)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = Array.Empty <Object>();
                DragAndDrop.paths            = Array.Empty <string>();
                _dragHandler?.AttachData(Result);
                this.ReleaseMouse();
                DragAndDrop.StartDrag("Dragging..");
                _dragState = DragState.Dragging;
            }
        }
Exemplo n.º 25
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");
        }
Exemplo n.º 26
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(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);
        }
Exemplo n.º 27
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();
                }
            }
        }
Exemplo n.º 28
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");
        }
Exemplo n.º 30
0
        /// <summary>
        /// Registers fieldRect for drag operations. dragObject is what's being dragged out of that field.
        /// </summary>
        public static void RegisterFieldForDrag(Rect fieldRect, UnityEngine.Object dragObject)
        {
            if (dragObject == null)
            {
                return;                     // can't drag a null wtf!
            }
            Event e = Event.current;

            if (fieldRect.Contains(e.mousePosition) && e.type == EventType.MouseDrag)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = new[] { dragObject };
                DragAndDrop.StartDrag("drag");
                Event.current.Use();
            }
        }