示例#1
0
        private void FinalizeDropObject()
        {
            if (this.WillDrop)
            {
                this.WillDrop                              = false;
                this.IsBeingClaimed                        = false;
                this.IsReadyToBeClaimed                    = false;
                this.isDragging                            = false;
                this.isMouseDown                           = false;
                this.IsHovering                            = false;
                currentHoveringDragHandle                  = null;
                DragAndDropManager.WasDragPerformed        = false;
                DragAndDropManager.CurrentDraggingHandle   = null;
                DragAndDropManager.CurrentHoveringDropZone = null;
                GUIHelper.RequestRepaint();

                if (this.OnDragFinnished != null)
                {
                    this.OnDragFinnished(this.dropEvent);
                }
            }
        }
示例#2
0
        internal void Update()
        {
            this.lastSeenEvent = Event.current.type;

            this.SetCurrentDragAndDropMethod();

            if (this.lastSeenEvent == EventType.Repaint)
            {
                this.FinalizeDropObject();
            }

            if (Event.current.isMouse || Event.current.type == EventType.DragUpdated)
            {
                Rect screenSpaceRect;

                if (this.DragHandleRect.HasValue)
                {
                    screenSpaceRect = this.DragHandleRect.Value;
                }
                else
                {
                    screenSpaceRect = this.Rect;
                }

                Vector2 screenPos = GUIUtility.GUIToScreenPoint(new Vector2(screenSpaceRect.x, screenSpaceRect.y));
                screenSpaceRect.x = screenPos.x;
                screenSpaceRect.y = screenPos.y;

                this.IsHovering = screenSpaceRect.Contains(GUIUtility.GUIToScreenPoint(Event.current.mousePosition));
            }

            this.OnDragStarted = false;

            if (DragAndDropManager.IsDragInProgress == false)
            {
                if (Event.current.isMouse)
                {
                    if (this.IsHovering)
                    {
                        if (this.Enabled && Event.current.type == EventType.MouseDown == true && Event.current.button == 0)
                        {
                            this.isMouseDown            = true;
                            this.mouseDownPostionOffset = Event.current.mousePosition - new Vector2(this.Rect.x, this.Rect.y);
                            GUIHelper.RemoveFocusControl();
                            Event.current.Use();
                            DragAndDrop.PrepareStartDrag();
                        }

                        if (this.isMouseDown && Event.current.type == EventType.MouseDrag)
                        {
                            this.isDragging    = true;
                            this.OnDragStarted = true;
                            if (this.Object != null)
                            {
                                DragAndDrop.objectReferences = new UnityEngine.Object[0];
                                DragAndDrop.paths            = null;
                                DragAndDrop.SetGenericData(this.Object.GetType().Name, this.Object);
                                DragAndDrop.StartDrag("Odin Drag Operation");
                            }
                        }
                    }
                }
            }
            else
            {
                GUIHelper.RequestRepaint();
            }

            if (this.isDragging)
            {
                GUIHelper.RequestRepaint();

                DragAndDropManager.CurrentDraggingHandle = this;

                if (EditorWindow.mouseOverWindow != null)
                {
                    EditorWindow.mouseOverWindow.Focus();
                }

                if (DragAndDropManager.WasDragPerformed)
                {
                    this.IsReadyToBeClaimed = true;

                    if (DragAndDropManager.IsHoveringDropZone == false)
                    {
                        this.DropObject(DropEvents.Canceled);
                    }
                }
            }
            else
            {
                if (this.IsHovering)
                {
                    if (currentHoveringDragHandle == null || this.LayoutDepth >= currentHoveringDragHandle.LayoutDepth)
                    {
                        currentHoveringDragHandle = this;
                    }
                }
                else if (currentHoveringDragHandle == this)
                {
                    currentHoveringDragHandle = null;
                }

                this.IsHovering = currentHoveringDragHandle == this;
            }
        }