public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            GroupNode firstAncestorOfType = base.parent.GetFirstAncestorOfType <GroupNode>();
            bool      flag = false;

            foreach (ISelectable current in selection)
            {
                if (current != firstAncestorOfType)
                {
                    GraphElement element    = current as GraphElement;
                    Event        imguiEvent = evt.imguiEvent;
                    if (imguiEvent.shift)
                    {
                        if (firstAncestorOfType.ContainsElement(element))
                        {
                            firstAncestorOfType.RemoveElement(element);
                        }
                    }
                    else if (!firstAncestorOfType.ContainsElement(element) && element.GetContainingGroupNode() == null)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                base.AddToClassList("dragEntered");
            }
            else
            {
                base.RemoveFromClassList("dragEntered");
            }
            return(EventPropagation.Stop);
        }
 private void SendDragAndDropEvent(IMGUIEvent evt, List <ISelectable> selection, IDropTarget dropTarget)
 {
     if (dropTarget != null && dropTarget.CanAcceptDrop(selection))
     {
         EventType type = evt.imguiEvent.type;
         if (type != EventType.DragUpdated)
         {
             if (type != EventType.DragPerform)
             {
                 if (type == EventType.DragExited)
                 {
                     dropTarget.DragExited();
                 }
             }
             else
             {
                 dropTarget.DragPerform(evt, selection, dropTarget);
             }
         }
         else
         {
             dropTarget.DragUpdated(evt, selection, dropTarget);
         }
     }
 }
Example #3
0
        void Handler(IMGUIEvent evt, List <ISelectable> selection, IDropTarget dropTarget)
        {
            if (dropTarget == null || !dropTarget.CanAcceptDrop(selection))
            {
                return;
            }

            var propagation = EventPropagation.Continue;

            if (evt.imguiEvent.type == EventType.DragUpdated)
            {
                propagation = dropTarget.DragUpdated(evt, selection, dropTarget);
            }
            else if (evt.imguiEvent.type == EventType.DragPerform)
            {
                propagation = dropTarget.DragPerform(evt, selection, dropTarget);
            }
            else if (evt.imguiEvent.type == EventType.DragExited)
            {
                propagation = dropTarget.DragExited();
            }

//            if (propagation == EventPropagation.Stop)
//                evt.StopPropagation();
        }
        void OnIMGUIEvent(IMGUIEvent evt)
        {
            if (evt.imguiEvent.type == EventType.DragUpdated || evt.imguiEvent.type == EventType.DragPerform)
            {
                var currentTarget = evt.currentTarget as VisualElement;
                if (currentTarget == null)
                {
                    return;
                }
                var    objects       = DragAndDrop.objectReferences;
                Object draggedObject = null;
                foreach (var obj in objects)
                {
                    if (ValidateObject(obj))
                    {
                        draggedObject = obj;
                        break;
                    }
                }
                if (draggedObject == null)
                {
                    return;
                }

//                Debug.LogFormat("{0}: {1}", draggedObject.GetType().Name, draggedObject.name);
                DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                if (evt.imguiEvent.type == EventType.DragPerform)
                {
                    var nodePosition = m_GraphView.contentViewContainer.transform.matrix.inverse.MultiplyPoint3x4(m_GraphView.panel.visualTree.ChangeCoordinatesTo(m_GraphView, Event.current.mousePosition));
                    CreateNode(draggedObject, nodePosition);
                    DragAndDrop.AcceptDrag();
                }
            }
        }
//        public bool DragUpdated(DragUpdatedEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
        public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            VisualElement sourceItem = null;

            foreach (ISelectable selectedElement in selection)
            {
                sourceItem = selectedElement as VisualElement;

                if (sourceItem == null)
                {
                    continue;
                }
            }

            if (!Contains(sourceItem))
            {
                SetDragIndicatorVisible(false);

                return(EventPropagation.Continue);
            }

            var target = evt.target as VisualElement;
//            Vector2 localPosition = target.ChangeCoordinatesTo(this, evt.localMousePosition);
            Vector2 localPosition = target.ChangeCoordinatesTo(this, evt.imguiEvent.mousePosition);

            m_InsertIndex = InsertionIndex(localPosition);

            if (m_InsertIndex != -1)
            {
                float indicatorY = 0;

                if (m_InsertIndex == childCount)
                {
                    VisualElement lastChild = this[childCount - 1];

                    indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.style.marginBottom)).y;
                }
                else
                {
                    VisualElement childAtInsertIndex = this[m_InsertIndex];

                    indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.style.marginTop)).y;
                }

                SetDragIndicatorVisible(true);

                m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height);

                return(EventPropagation.Stop);
            }
            else
            {
                SetDragIndicatorVisible(false);

                m_InsertIndex = -1;

                return(EventPropagation.Continue);
            }
        }
 protected new void OnMouseUp(MouseUpEvent evt)
 {
     if (this.m_GraphView == null)
     {
         if (this.m_Active && base.target.HasMouseCapture())
         {
             base.target.ReleaseMouseCapture();
             this.selectedElement  = null;
             this.m_Active         = false;
             this.m_PrevDropTarget = null;
         }
     }
     else
     {
         List <ISelectable> selection = this.m_GraphView.selection;
         if (base.CanStopManipulation(evt))
         {
             if (this.m_Active && base.target.HasMouseCapture())
             {
                 if (this.selectedElement == null)
                 {
                     this.m_MovedElements.Clear();
                     foreach (GraphElement current in this.m_OriginalPos.Keys)
                     {
                         current.UpdatePresenterPosition();
                         this.m_MovedElements.Add(current);
                     }
                     GraphView graphView = base.target as GraphView;
                     if (graphView != null && graphView.graphViewChanged != null)
                     {
                         graphView.graphViewChanged(this.m_GraphViewChange);
                     }
                 }
                 this.m_PanSchedule.Pause();
                 if (this.m_ItemPanDiff != Vector3.zero)
                 {
                     Vector3 position = this.m_GraphView.contentViewContainer.transform.position;
                     Vector3 scale    = this.m_GraphView.contentViewContainer.transform.scale;
                     this.m_GraphView.UpdateViewTransform(position, scale);
                 }
                 if (selection.Count > 0 && this.m_PrevDropTarget != null)
                 {
                     using (IMGUIEvent pooled = IMGUIEvent.GetPooled(evt.imguiEvent))
                     {
                         pooled.imguiEvent.type = EventType.DragPerform;
                         this.SendDragAndDropEvent(pooled, selection, this.m_PrevDropTarget);
                     }
                 }
                 base.target.ReleaseMouseCapture();
                 evt.StopPropagation();
             }
             this.selectedElement  = null;
             this.m_Active         = false;
             this.m_PrevDropTarget = null;
         }
     }
 }
Example #7
0
 void OnRecorderListIMGUI(IMGUIEvent evt)
 {
     if (evt.imguiEvent.type == EventType.ValidateCommand)
     {
         RecorderListValidateCommand(evt, evt.imguiEvent.commandName);
     }
     else if (evt.imguiEvent.type == EventType.ExecuteCommand)
     {
         RecorderListExecuteCommand(evt, evt.imguiEvent.commandName);
     }
 }
 protected new void OnMouseMove(MouseMoveEvent e)
 {
     if (!base.target.HasMouseCapture())
     {
         this.m_PrevDropTarget = null;
         this.m_Active         = false;
     }
     if (this.m_Active)
     {
         if (this.m_GraphView != null)
         {
             VisualElement src      = (VisualElement)e.target;
             Vector2       mousePos = src.ChangeCoordinatesTo(this.m_GraphView.contentContainer, e.localMousePosition);
             this.m_PanDiff = this.GetEffectivePanSpeed(mousePos);
             if (this.m_PanDiff != Vector3.zero)
             {
                 this.m_PanSchedule.Resume();
             }
             else
             {
                 this.m_PanSchedule.Pause();
             }
             this.m_MouseDiff = this.m_originalMouse - e.mousePosition;
             foreach (KeyValuePair <GraphElement, Rect> current in this.m_OriginalPos)
             {
                 GraphElement key            = current.Key;
                 Matrix4x4    worldTransform = key.worldTransform;
                 Vector3      vector         = new Vector3(worldTransform.m00, worldTransform.m11, worldTransform.m22);
                 Rect         position       = key.GetPosition();
                 key.SetPosition(new Rect(current.Value.x - (this.m_MouseDiff.x - this.m_ItemPanDiff.x) * base.panSpeed.x / vector.x, current.Value.y - (this.m_MouseDiff.y - this.m_ItemPanDiff.y) * base.panSpeed.y / vector.y, position.width, position.height));
             }
             List <ISelectable> selection    = this.m_GraphView.selection;
             IDropTarget        dropTargetAt = this.GetDropTargetAt(e.localMousePosition);
             if (this.m_PrevDropTarget != dropTargetAt && this.m_PrevDropTarget != null)
             {
                 using (IMGUIEvent pooled = IMGUIEvent.GetPooled(e.imguiEvent))
                 {
                     pooled.imguiEvent.type = EventType.DragExited;
                     this.SendDragAndDropEvent(pooled, selection, this.m_PrevDropTarget);
                 }
             }
             using (IMGUIEvent pooled2 = IMGUIEvent.GetPooled(e.imguiEvent))
             {
                 pooled2.imguiEvent.type = EventType.DragUpdated;
                 this.SendDragAndDropEvent(pooled2, selection, dropTargetAt);
             }
             this.m_PrevDropTarget = dropTargetAt;
             this.selectedElement  = null;
             e.StopPropagation();
         }
     }
 }
Example #9
0
            protected internal override void ExecuteDefaultActionAtTarget(EventBase evt)
            {
                base.ExecuteDefaultActionAtTarget(evt);

                if (evt.GetEventTypeId() == MouseDownEvent.TypeId())
                {
                    OnMouseDown();
                }
                else if (evt.GetEventTypeId() == IMGUIEvent.TypeId())
                {
                    OnIMGUI(evt);
                }
                else if (evt.GetEventTypeId() == MouseLeaveEvent.TypeId())
                {
                    OnMouseLeave();
                }
            }
        public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            GroupNode firstAncestorOfType = base.parent.GetFirstAncestorOfType <GroupNode>();

            foreach (ISelectable current in selection)
            {
                if (current != firstAncestorOfType)
                {
                    GraphElement element = current as GraphElement;
                    if (!firstAncestorOfType.ContainsElement(element) && element.GetContainingGroupNode() == null)
                    {
                        firstAncestorOfType.AddElement(element);
                    }
                }
            }
            base.RemoveFromClassList("dragEntered");
            return(EventPropagation.Stop);
        }
        protected void OnIMGUIEvent(IMGUIEvent e)
        {
            Event evt = e.imguiEvent;


            VFXObjectField target = this.target as VFXObjectField;

            switch (evt.type)
            {
            case EventType.DragUpdated:
            {
                var matchingObjects = DragAndDrop.objectReferences.Where(t => target.editedType.IsAssignableFrom(t.GetType())).ToArray();

                if (matchingObjects.Length > 0)
                {
                    //target.AddToClassList("droppable");
                    DragAndDrop.visualMode = evt.control ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move;
                    e.StopPropagation();
                }

                break;
            }

            case EventType.DragExited:
            {
                //target.RemoveFromClassList("droppable");
                break;
            }

            case EventType.DragPerform:
            {
                //target.RemoveFromClassList("droppable");
                var matchingObjects = DragAndDrop.objectReferences.Where(t => target.editedType.IsAssignableFrom(t.GetType())).ToArray();

                if (matchingObjects.Length > 0)
                {
                    target.ValueChanged(matchingObjects[0]);
                    e.StopPropagation();
                }
                break;
            }
            }
        }
Example #12
0
        public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            GroupNode group   = parent.GetFirstAncestorOfType <GroupNode>();
            bool      canDrop = false;

            foreach (ISelectable selectedElement in selection)
            {
                if (selectedElement == group)
                {
                    continue;
                }

                var   selectedGraphElement = selectedElement as GraphElement;
                Event e = evt.imguiEvent;

                if (e.shift)
                {
                    if (group.ContainsElement(selectedGraphElement))
                    {
                        group.RemoveElement(selectedGraphElement);
                    }
                }
                else
                {
                    if (!group.ContainsElement(selectedGraphElement) && selectedGraphElement.GetContainingGroupNode() == null)
                    {
                        canDrop = true;
                    }
                }
            }

            if (canDrop)
            {
                AddToClassList("dragEntered");
            }
            else
            {
                RemoveFromClassList("dragEntered");
            }

            return(EventPropagation.Stop);
        }
Example #13
0
        public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            GroupNode group = parent.GetFirstAncestorOfType <GroupNode>();

            foreach (ISelectable selectedElement in selection)
            {
                if (selectedElement != group)
                {
                    var selectedGraphElement = selectedElement as GraphElement;

                    if (group.ContainsElement(selectedGraphElement) || selectedGraphElement.GetContainingGroupNode() != null)
                    {
                        continue;
                    }

                    group.AddElement(selectedGraphElement);
                }
            }

            RemoveFromClassList("dragEntered");

            return(EventPropagation.Stop);
        }
Example #14
0
        void SendDragAndDropEvent(IMGUIEvent evt, List <ISelectable> selection, IDropTarget dropTarget)
        {
            if (dropTarget == null || !dropTarget.CanAcceptDrop(selection))
            {
                return;
            }
            switch (evt.imguiEvent.type)
            {
            case EventType.DragPerform:
                dropTarget.DragPerform(evt, selection, dropTarget);
                break;

            case EventType.DragUpdated:
                dropTarget.DragUpdated(evt, selection, dropTarget);
                break;

            case EventType.DragExited:
                dropTarget.DragExited();
                break;

            default:
                break;
            }
        }
Example #15
0
        protected void OnIMGUIEvent(IMGUIEvent e)
        {
            if (!m_Active || selectionContainer == null)
            {
                return;
            }

            // Keep a copy of the selection
            var selection = selectionContainer.selection.ToList();

            Event evt = e.imguiEvent;

            switch (evt.type)
            {
            case EventType.DragUpdated:
            {
                if (target.HasMouseCapture() && evt.button == (int)activateButton && selection.Count > 0)
                {
                    selectedElement = null;

                    // TODO: Replace with a temp drawing or something...maybe manipulator could fake position
                    // all this to let operation know which element sits under cursor...or is there another way to draw stuff that is being dragged?

                    if (OnDrop != null)
                    {
                        var         pickElem   = target.panel.Pick(target.LocalToWorld(evt.mousePosition));
                        IDropTarget dropTarget = pickElem != null?pickElem.GetFirstAncestorOfType <IDropTarget>() : null;

                        if (prevDropTarget != dropTarget && prevDropTarget != null)
                        {
                            using (IMGUIEvent eexit = IMGUIEvent.GetPooled(e.imguiEvent))
                            {
                                eexit.imguiEvent.type = EventType.DragExited;
                                OnDrop(eexit, selection, prevDropTarget);
                            }
                        }
                        OnDrop(e, selection, dropTarget);
                        prevDropTarget = dropTarget;
                    }

                    DragAndDrop.visualMode = evt.control ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move;
                }

                break;
            }

            case EventType.DragExited:
            {
                if (OnDrop != null && prevDropTarget != null)
                {
                    OnDrop(e, selection, prevDropTarget);
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.None;
                DragAndDrop.SetGenericData("DragSelection", null);

                prevDropTarget = null;
                m_Active       = false;
                target.ReleaseMouseCapture();
                break;
            }

            case EventType.DragPerform:
            {
                if (m_Active && evt.button == (int)activateButton && selection.Count > 0)
                {
                    if (selection.Count > 0)
                    {
                        if (OnDrop != null)
                        {
                            var         pickElem   = target.panel.Pick(target.LocalToWorld(evt.mousePosition));
                            IDropTarget dropTarget = pickElem != null?pickElem.GetFirstAncestorOfType <IDropTarget>() : null;

                            OnDrop(e, selection, dropTarget);
                        }

                        DragAndDrop.visualMode = DragAndDropVisualMode.None;
                        DragAndDrop.SetGenericData("DragSelection", null);
                    }
                }

                prevDropTarget = null;
                m_Active       = false;
                target.ReleaseMouseCapture();
                break;
            }
            }
        }
Example #16
0
 public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
 {
     return(EventPropagation.Continue);
 }
//        public bool DragPerform(DragPerformEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
        public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            if (m_InsertIndex != -1)
            {
                List <VisualElementPair> draggedElements = new List <VisualElementPair>();

                foreach (ISelectable selectedElement in selection)
                {
                    var draggedElement = selectedElement as VisualElement;

                    if (draggedElement != null && Contains(draggedElement))
                    {
                        draggedElements.Add(new VisualElementPair(FindSectionDirectChild(draggedElement), draggedElement));
                    }
                }

                if (draggedElements.Count == 0)
                {
                    SetDragIndicatorVisible(false);

                    return(EventPropagation.Continue);
                }

                // Sorts the dragged elements from their relative order in their parent
                draggedElements.Sort((pair1, pair2) => { return(IndexOf(pair1.Item1).CompareTo(IndexOf(pair2.Item1))); });

                int insertIndex = m_InsertIndex;

                foreach (var draggedElement in draggedElements)
                {
                    VisualElement sectionDirectChild    = draggedElement.Item1;
                    int           indexOfDraggedElement = IndexOf(sectionDirectChild);

                    if (!((indexOfDraggedElement == insertIndex) || ((insertIndex - 1) == indexOfDraggedElement)))
                    {
                        Blackboard blackboard = GetFirstAncestorOfType <Blackboard>();

                        if (blackboard.moveItemRequested != null)
                        {
                            blackboard.moveItemRequested(blackboard, m_InsertIndex, draggedElement.Item2);
                        }
                        else
                        {
                            if (insertIndex == contentContainer.childCount)
                            {
                                sectionDirectChild.BringToFront();
                            }
                            else
                            {
                                sectionDirectChild.PlaceBehind(this[insertIndex]);
                            }
                        }
                    }

                    if (insertIndex > indexOfDraggedElement) // No need to increment the insert index for the next dragged element if the current dragged element is above the current insert location.
                    {
                        continue;
                    }
                    insertIndex++;
                }
            }

            SetDragIndicatorVisible(false);

            return(EventPropagation.Stop);
        }
Example #18
0
        protected new void OnMouseMove(MouseMoveEvent e)
        {
            if (!target.HasMouseCapture())
            {
                // We lost the capture. Since we still receive mouse events,
                // the MouseDown target must have taken it in its ExecuteDefaultAction().
                // Stop processing the event sequence, then.
                // FIXME: replace this by a handler on the upcoming LostCaptureEvent.

                m_PrevDropTarget = null;
                m_Active         = false;
            }

            if (!m_Active)
            {
                return;
            }

            if (m_GraphView == null)
            {
                return;
            }

            var     ve         = (VisualElement)e.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(m_GraphView.contentContainer, e.localMousePosition);

            m_PanDiff = GetEffectivePanSpeed(gvMousePos);


            if (m_PanDiff != Vector3.zero)
            {
                m_PanSchedule.Resume();
            }
            else
            {
                m_PanSchedule.Pause();
            }

            // We need to monitor the mouse diff "by hand" because we stop positionning the graph elements once the
            // mouse has gone out.
            m_MouseDiff = m_originalMouse - e.mousePosition;

            foreach (KeyValuePair <GraphElement, Rect> v in m_OriginalPos)
            {
                GraphElement ce = v.Key;

                Matrix4x4 g     = ce.worldTransform;
                var       scale = new Vector3(g.m00, g.m11, g.m22);

                Rect ceLayout = ce.GetPosition();

                ce.SetPosition(
                    new Rect(v.Value.x - (m_MouseDiff.x - m_ItemPanDiff.x) * panSpeed.x / scale.x,
                             v.Value.y - (m_MouseDiff.y - m_ItemPanDiff.y) * panSpeed.y / scale.y,
                             ceLayout.width, ceLayout.height));
            }
            List <ISelectable> selection = m_GraphView.selection;

            // TODO: Replace with a temp drawing or something...maybe manipulator could fake position
            // all this to let operation know which element sits under cursor...or is there another way to draw stuff that is being dragged?

            IDropTarget dropTarget = GetDropTargetAt(e.localMousePosition);

            if (m_PrevDropTarget != dropTarget && m_PrevDropTarget != null)
            {
                using (IMGUIEvent eexit = IMGUIEvent.GetPooled(e.imguiEvent))
                {
                    eexit.imguiEvent.type = EventType.DragExited;
                    SendDragAndDropEvent(eexit, selection, m_PrevDropTarget);
                }
            }

            using (IMGUIEvent eupdated = IMGUIEvent.GetPooled(e.imguiEvent))
            {
                eupdated.imguiEvent.type = EventType.DragUpdated;
                SendDragAndDropEvent(eupdated, selection, dropTarget);
            }

            m_PrevDropTarget = dropTarget;

            selectedElement = null;
            e.StopPropagation();
        }
Example #19
0
        protected new void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active && target.HasMouseCapture())
                {
                    target.ReleaseMouseCapture();
                    selectedElement  = null;
                    m_Active         = false;
                    m_PrevDropTarget = null;
                }

                return;
            }

            List <ISelectable> selection = m_GraphView.selection;

            if (CanStopManipulation(evt))
            {
                if (m_Active && target.HasMouseCapture())
                {
                    if (selectedElement == null)
                    {
                        m_MovedElements.Clear();
                        foreach (GraphElement ce in m_OriginalPos.Keys)
                        {
                            ce.UpdatePresenterPosition();

                            m_MovedElements.Add(ce);
                        }

                        var graphView = target as GraphView;
                        if (graphView != null && graphView.graphViewChanged != null)
                        {
                            graphView.graphViewChanged(m_GraphViewChange);
                        }
                    }

                    m_PanSchedule.Pause();

                    if (m_ItemPanDiff != Vector3.zero)
                    {
                        Vector3 p = m_GraphView.contentViewContainer.transform.position;
                        Vector3 s = m_GraphView.contentViewContainer.transform.scale;
                        m_GraphView.UpdateViewTransform(p, s);
                    }

                    if (selection.Count > 0 && m_PrevDropTarget != null)
                    {
                        using (IMGUIEvent drop = IMGUIEvent.GetPooled(evt.imguiEvent))
                        {
                            drop.imguiEvent.type = EventType.DragPerform;
                            SendDragAndDropEvent(drop, selection, m_PrevDropTarget);
                        }
                    }

                    target.ReleaseMouseCapture();
                    evt.StopPropagation();
                }
                selectedElement  = null;
                m_Active         = false;
                m_PrevDropTarget = null;
            }
        }
Example #20
0
        void OnIMGUIEvent(IMGUIEvent evt)
        {
            if (evt.imguiEvent.type == EventType.DragUpdated || evt.imguiEvent.type == EventType.DragPerform)
            {
                try
                {
                    var currentTarget = evt.currentTarget as VisualElement;
                    if (currentTarget == null)
                    {
                        return;
                    }
                    var pickElement = currentTarget.panel.Pick(target.LocalToWorld(evt.imguiEvent.mousePosition));
                    if (m_Selection == null)
                    {
                        m_Selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>;
                    }
                    if (!(pickElement is MaterialGraphView))
                    {
                        return;
                    }
                    var objects = DragAndDrop.objectReferences;

                    if (m_Selection != null)
                    {
                        // Handle drop of UIElements
                        if (m_Selection.OfType <BlackboardField>().Count() != 1)
                        {
                            m_Selection = null;
                            return;
                        }
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        if (evt.imguiEvent.type == EventType.DragPerform)
                        {
                            var nodePosition = m_GraphView.contentViewContainer.transform.matrix.inverse.MultiplyPoint3x4(m_GraphView.panel.visualTree.ChangeCoordinatesTo(m_GraphView, Event.current.mousePosition));
                            CreateNode(m_Selection.First(), nodePosition);
                            DragAndDrop.AcceptDrag();
                        }
                    }
                    else
                    {
                        // Handle drop of Unity objects
                        Object draggedObject = null;
                        foreach (var obj in objects)
                        {
                            if (ValidateObject(obj))
                            {
                                draggedObject = obj;
                                break;
                            }
                        }
                        if (draggedObject != null)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                            if (evt.imguiEvent.type == EventType.DragPerform)
                            {
                                var nodePosition = m_GraphView.contentViewContainer.transform.matrix.inverse.MultiplyPoint3x4(m_GraphView.panel.visualTree.ChangeCoordinatesTo(m_GraphView, Event.current.mousePosition));
                                CreateNode(draggedObject, nodePosition);
                                DragAndDrop.AcceptDrag();
                            }
                        }
                    }
                }
                finally
                {
                    if (evt.imguiEvent.type == EventType.DragPerform || evt.imguiEvent.type == EventType.DragExited)
                    {
                        m_Selection = null;
                    }
                }
            }
        }
Example #21
0
 protected void OnIMGUIEvent(IMGUIEvent e)
 {
     if (this.m_Active && this.selectionContainer != null)
     {
         List <ISelectable> list = this.selectionContainer.selection.ToList <ISelectable>();
         Event     imguiEvent    = e.imguiEvent;
         EventType type          = imguiEvent.type;
         if (type != EventType.DragUpdated)
         {
             if (type != EventType.DragExited)
             {
                 if (type == EventType.DragPerform)
                 {
                     if (this.m_Active && imguiEvent.button == (int)this.activateButton && list.Count > 0)
                     {
                         if (list.Count > 0)
                         {
                             if (this.OnDrop != null)
                             {
                                 VisualElement visualElement = base.target.panel.Pick(base.target.LocalToWorld(imguiEvent.mousePosition));
                                 IDropTarget   dropTarget    = (visualElement == null) ? null : visualElement.GetFirstAncestorOfType <IDropTarget>();
                                 this.OnDrop(e, list, dropTarget);
                             }
                             DragAndDrop.visualMode = DragAndDropVisualMode.None;
                             DragAndDrop.SetGenericData("DragSelection", null);
                         }
                     }
                     this.prevDropTarget = null;
                     this.m_Active       = false;
                     base.target.ReleaseMouseCapture();
                 }
             }
             else
             {
                 if (this.OnDrop != null && this.prevDropTarget != null)
                 {
                     this.OnDrop(e, list, this.prevDropTarget);
                 }
                 DragAndDrop.visualMode = DragAndDropVisualMode.None;
                 DragAndDrop.SetGenericData("DragSelection", null);
                 this.prevDropTarget = null;
                 this.m_Active       = false;
                 base.target.ReleaseMouseCapture();
             }
         }
         else if (base.target.HasMouseCapture() && imguiEvent.button == (int)this.activateButton && list.Count > 0)
         {
             this.selectedElement = null;
             if (this.OnDrop != null)
             {
                 VisualElement visualElement2 = base.target.panel.Pick(base.target.LocalToWorld(imguiEvent.mousePosition));
                 IDropTarget   dropTarget2    = (visualElement2 == null) ? null : visualElement2.GetFirstAncestorOfType <IDropTarget>();
                 if (this.prevDropTarget != dropTarget2 && this.prevDropTarget != null)
                 {
                     using (IMGUIEvent pooled = IMGUIEvent.GetPooled(e.imguiEvent))
                     {
                         pooled.imguiEvent.type = EventType.DragExited;
                         this.OnDrop(pooled, list, this.prevDropTarget);
                     }
                 }
                 this.OnDrop(e, list, dropTarget2);
                 this.prevDropTarget = dropTarget2;
             }
             DragAndDrop.visualMode = ((!imguiEvent.control) ? DragAndDropVisualMode.Move : DragAndDropVisualMode.Copy);
         }
     }
 }