コード例 #1
0
        public void Draw(GraphRendererContext rendererContext, GraphCamera camera)
        {
            if (!active)
            {
                return;
            }

            var mouseWorld = camera.ScreenToWorld(mouseScreenPosition);

            mousePin.Position = mouseWorld;


            GraphLinkRenderer.DrawGraphLink(rendererContext, link, camera);

            // Check the pin that comes under the mouse pin
            var targetPin = graphEditor.GetPinUnderPosition(mouseWorld);

            if (targetPin != null)
            {
                var sourcePin = attachedPin;
                var pins      = new GraphPin[] { sourcePin, targetPin };
                Array.Sort(pins, new GraphPinHierarchyComparer());
                string errorMessage;
                if (!GraphSchema.CanCreateLink(pins[0], pins[1], out errorMessage))
                {
                    GraphTooltip.message = errorMessage;
                }
            }
        }
コード例 #2
0
ファイル: GraphOperations.cs プロジェクト: Borgeshc/Game
        /// <summary>
        /// Handles user input (keyboard and mouse)
        /// </summary>
        /// <param name="e">Input event</param>
        /// <param name="camera">Graph camera to convert to / from screen to world coordinates</param>
        /// <returns>true if the input was processed, false otherwise.</returns>
        public static bool HandleNodeInput(GraphNode node, Event e, GraphCamera camera)
        {
            bool inputProcessed = false;

            if (!node.Dragging)
            {
                // let the pins handle the input first
                foreach (var pin in node.InputPins)
                {
                    if (inputProcessed)
                    {
                        break;
                    }
                    inputProcessed |= HandlePinInput(pin, e, camera);
                }
                foreach (var pin in node.OutputPins)
                {
                    if (inputProcessed)
                    {
                        break;
                    }
                    inputProcessed |= HandlePinInput(pin, e, camera);
                }
            }

            var mousePosition      = e.mousePosition;
            var mousePositionWorld = camera.ScreenToWorld(mousePosition);
            int dragButton         = 0;

            // If the pins didn't already handle the input, then let the node handle it
            if (!inputProcessed)
            {
                bool insideRect = node.Bounds.Contains(mousePositionWorld);
                if (e.type == EventType.MouseDown && insideRect && e.button == dragButton)
                {
                    node.Dragging  = true;
                    inputProcessed = true;
                }
                else if (e.type == EventType.MouseUp && insideRect && e.button == dragButton)
                {
                    node.Dragging = false;
                }
            }

            if (node.Dragging && !node.Selected)
            {
                node.Dragging = false;
            }

            if (node.Dragging && e.type == EventType.MouseDrag)
            {
                inputProcessed = true;
            }

            return(inputProcessed);
        }
コード例 #3
0
ファイル: GraphOperations.cs プロジェクト: Borgeshc/Game
        /// <summary>
        /// Handles the mouse input and returns true if handled
        /// </summary>
        public static bool HandlePinInput(GraphPin pin, Event e, GraphCamera camera)
        {
            var mousePosition        = e.mousePosition;
            var mousePositionWorld   = camera.ScreenToWorld(mousePosition);
            int buttonIdDrag         = 0;
            int buttonIdDestroyLinks = 1;

            if (pin.ContainsPoint(mousePositionWorld))
            {
                if (e.type == EventType.MouseDown && e.button == buttonIdDrag)
                {
                    pin.ClickState = GraphPinMouseState.Clicked;
                    return(true);
                }

                if (e.button == buttonIdDestroyLinks)
                {
                    if (e.type == EventType.MouseDown)
                    {
                        pin.RequestLinkDeletionInitiated = true;
                    }
                    else if (e.type == EventType.MouseDrag)
                    {
                        pin.RequestLinkDeletionInitiated = false;
                    }
                    else if (e.type == EventType.MouseUp)
                    {
                        if (pin.RequestLinkDeletionInitiated)
                        {
                            DestroyPinLinks(pin);
                            if (pin.Node != null && pin.Node.Graph != null)
                            {
                                pin.Node.Graph.NotifyStateChanged();
                            }
                        }
                    }
                    return(true);
                }

                if (pin.ClickState != GraphPinMouseState.Clicked)
                {
                    pin.ClickState = GraphPinMouseState.Hover;
                }
            }
            else
            {
                pin.ClickState = GraphPinMouseState.None;
            }

            return(false);
        }
コード例 #4
0
        void HandleSelect(Event e)
        {
            // Update the node selected flag
            var mousePosition      = e.mousePosition;
            var mousePositionWorld = camera.ScreenToWorld(mousePosition);
            var buttonId           = 0;

            if (e.type == EventType.MouseDown && e.button == buttonId)
            {
                bool multiSelect  = keyboardState.ShiftPressed;
                bool toggleSelect = keyboardState.ControlPressed;
                // sort the nodes front to back
                GraphNode[] sortedNodes = graph.Nodes.ToArray();
                System.Array.Sort(sortedNodes, new NodeReversedZIndexComparer());

                GraphNode mouseOverNode = null;
                foreach (var node in sortedNodes)
                {
                    var mouseOver = node.Bounds.Contains(mousePositionWorld);
                    if (mouseOver)
                    {
                        mouseOverNode = node;
                        break;
                    }
                }

                foreach (var node in sortedNodes)
                {
                    var mouseOver = (node == mouseOverNode);

                    if (mouseOverNode != null && mouseOverNode.Selected && !toggleSelect)
                    {
                        multiSelect = true;     // select multi-select so that we can drag multiple objects
                    }
                    if (multiSelect || toggleSelect)
                    {
                        if (mouseOver && multiSelect)
                        {
                            node.Selected = true;
                        }
                        else if (mouseOver && toggleSelect)
                        {
                            node.Selected = !node.Selected;
                        }
                    }
                    else
                    {
                        node.Selected = mouseOver;
                    }

                    if (node.Selected)
                    {
                        BringToFront(node);
                    }
                }

                if (mouseOverNode == null)
                {
                    // No nodes were selected
                    Selection.activeObject = null;
                }

                OnNodeSelectionChanged();
            }
        }