Esempio n. 1
0
        public void OnUnLinked(Graph graph, AbstractSocket s01, AbstractSocket s02)
        {
            Log.Info("OnUnLinked: Socket " + s02 + " and Socket " + s02);
            AbstractSocket input = s01.IsInput() ? s01 : s02;

            graph.UpdateDependingNodes(input.Parent);
        }
Esempio n. 2
0
        public void DrawEdges(Rect canvasAreaInWindow)
        {
            if (_draggingPathPointIndex == -1)
            {
                _hoveringEdge = null;
            }

            for (var i = 0; i < Graph.GetNodeCount(); i++)
            {
                Node node = Graph.GetNodeAt(i);


                for (var iu = 0; iu < node.Sockets.Count; iu++)
                {
                    AbstractSocket socket = node.Sockets[iu];
                    if (socket.IsInput() && socket.IsConnected())                     // draw only input sockets to avoid double drawing of edges
                    {
                        InputSocket inputSocket = (InputSocket)socket;
                        if (CanvasOverlapsWindow(inputSocket.Edge.Bounds, canvasAreaInWindow))
                        {
                            bool highlight = _selectedNodes.Contains(node) ||
                                             _selectedNodes.Contains(inputSocket.Edge.Output.Parent);
                            int  segmentIndex = inputSocket.Edge.IntersectsPathSegment(Event.current.mousePosition);
                            bool hover        = segmentIndex > -1;
                            node.GUIDrawEdge(inputSocket, highlight, hover);
                            if (hover && _draggingPathPointIndex == -1)
                            {
                                HandleEdgeHover(inputSocket.Edge, segmentIndex);
                                _hoveringEdge = inputSocket.Edge;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void UnLink(AbstractSocket socket)
        {
            if (socket == null || !socket.IsConnected())
            {
                return;
            }


            if (socket.IsInput())
            {
                InputSocket inputSocket = (InputSocket)socket;
                if (inputSocket.Edge != null)
                {
                    UnLink(inputSocket, inputSocket.Edge.Output);
                }
            }

            if (socket.IsOutput())
            {
                OutputSocket outputSocket = (OutputSocket)socket;
                Edge[]       edgeCopy     = new Edge[outputSocket.Edges.Count];
                outputSocket.Edges.CopyTo(edgeCopy);
                for (int index = 0; index < edgeCopy.Length; index++)
                {
                    var edge = edgeCopy[index];
                    UnLink(edge.Input, outputSocket);
                }
            }
        }
Esempio n. 4
0
 private void HandleSocketDrop(AbstractSocket dropTarget)
 {
     if (dropTarget != null && dropTarget.GetType() != _dragSourceSocket.GetType())
     {
         if (dropTarget.IsInput())
         {
             _currentCanvas.Graph.Link((InputSocket)dropTarget, (OutputSocket)_dragSourceSocket);
         }
         Event.current.Use();
     }
     _dragSourceSocket = null;
     Repaint();
 }
Esempio n. 5
0
 private void HandleSocketDrag(AbstractSocket dragSource)
 {
     if (dragSource != null)
     {
         if (dragSource.IsInput() && dragSource.IsConnected())
         {
             _dragSourceSocket = ((InputSocket)dragSource).Edge.GetOtherSocket(dragSource);
             _currentCanvas.Graph.UnLink((InputSocket)dragSource, (OutputSocket)_dragSourceSocket);
         }
         if (dragSource.IsOutput())
         {
             _dragSourceSocket = dragSource;
         }
         Event.current.Use();
     }
     Repaint();
 }
Esempio n. 6
0
        protected override void OnGUI()
        {
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;
            Height = SocketTopOffsetInput + (_entitiesCount + _landscapeCount) * 20 + 25;

            _tmpRect.Set(3, 0, 120, 20);
            if (GUI.Button(_tmpRect, "add landscape"))
            {
                AddLandscapeSocket();
                TriggerChangeEvent();
            }

            _tmpRect.Set(3, 20, 120, 20);
            if (GUI.Button(_tmpRect, "add entities"))
            {
                AddGameObjectsSocket();
                TriggerChangeEvent();
            }

            float topOffset = SocketTopOffsetInput;

            InputSocket removeSocket = null;

            for (int i = 0; i < Sockets.Count; i++)
            {
                AbstractSocket socket = Sockets[i];
                if (socket.Type == typeof(ILandscapeConnection) || socket.Type == typeof(IEntitiesConnection) && socket.IsInput())
                {
                    InputSocket s = socket as InputSocket;
                    if (s.IsConnected())
                    {
                        _tmpRect.Set(3, topOffset, 100, 20);
                        Node connectedNode = s.Edge.GetOtherSocket(s).Parent;
                        GUI.Label(_tmpRect, connectedNode.Name + " (" + connectedNode.Id + ")");
                    }
                    else
                    {
                        _tmpRect.Set(3, topOffset, 20, 20);
                        if (GUI.Button(_tmpRect, "x"))
                        {
                            removeSocket = s;
                        }
                    }
                    topOffset += 20;
                }
            }

            if (removeSocket != null)
            {
                RemoveSocket(removeSocket);
            }
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
        }