Beispiel #1
0
 public static Vector2 GetTangentPosition(Socket socket, Vector2 position)
 {
     if (socket.Direction == SocketDirection.Input)
         return position + Vector2.left*BonConfig.EdgeTangent;
     else
         return position + Vector2.right*BonConfig.EdgeTangent;
 }
 public MathDisplay(int id)
     : base(id)
 {
     _inSocket = new Socket(this, NumberNode.FloatType, SocketDirection.Input);
     Sockets.Add(_inSocket);
     Sockets.Add(new Socket(this, NumberNode.FloatType, SocketDirection.Output));
     Height = 20 + BonConfig.SocketOffsetTop;
 }
 public MathOperatorNode(int id)
     : base(id)
 {
     _inputSocket01 = new Socket(this, NumberNode.FloatType, SocketDirection.Input);
     Sockets.Add(_inputSocket01);
     _inputSocket02 = new Socket(this, NumberNode.FloatType, SocketDirection.Input);
     Sockets.Add(_inputSocket02);
     Sockets.Add(new Socket(this, NumberNode.FloatType, SocketDirection.Output));
     Height = 95;
     Width = 80;
 }
 public override object GetResultOf(Socket outSocket)
 {
     if (CanGetResultOf(outSocket))
     {
         return UpdateValue();
     }
     else
     {
         return float.NaN;
     }
 }
Beispiel #5
0
 public static Vector2 GetEdgePosition(Socket socket, Vector2 position)
 {
     float width = 0;
     if (socket.Direction == SocketDirection.Output)
     {
         width = BonConfig.SocketSize;
     }
     position.Set(
         socket.X + width,
         socket.Y + (BonConfig.SocketSize/2f));
     return position;
 }
Beispiel #6
0
 public Edge(Socket socket01, Socket socket02)
 {
     if (socket01.Direction == SocketDirection.Input)
     {
         Input = socket01;
         Output = socket02;
     }
     else
     {
         Input = socket02;
         Output = socket01;
     }
 }
        public override object GetResultOf(Socket outSocket)
        {
            if (!CanGetResultOf(outSocket)) return float.NaN;

            Socket connectedSocket01 = _inputSocket01.GetConnectedSocket();
            Socket connectedSocket02 = _inputSocket02.GetConnectedSocket();
            Node connectedNode01 = connectedSocket01.Parent;
            Node connectedNode02 = connectedSocket02.Parent;

            float value01 = (float) connectedNode01.GetResultOf(connectedSocket01);
            float value02 = (float) connectedNode02.GetResultOf(connectedSocket02);

            if (!float.IsNaN(value01) && !float.IsNaN(value02))
            {
                return Calculate(value01, value02);
            }

            return float.NaN;
        }
        public void Draw(EditorWindow window, Rect region, Socket currentDragingSocket)
        {
            EditorZoomArea.Begin(Zoom, region);

            if (this.Style.normal.background == null) 	this.Style.normal.background = CreateBackgroundTexture();
            GUI.DrawTextureWithTexCoords(this.DrawArea, this.Style.normal.background, new Rect(0, 0, 1000, 1000));
            this.DrawArea.Set(this.Position.x, this.Position.y, CanvasSize, CanvasSize);
            GUILayout.BeginArea(this.DrawArea);
            this.DrawEdges();
            window.BeginWindows();
            this.DrawNodes();
            window.EndWindows();
            this.DrawDragEdge(currentDragingSocket);

            for (var i = 0; i < Graph.GetNodeCount(); i++)
            {
                Graph.GetNodeAt(i).GUIDrawSockets();
            }

            GUILayout.EndArea();
            EditorZoomArea.End();
        }
Beispiel #9
0
 public abstract object GetResultOf(Socket outSocket);
Beispiel #10
0
 /// <summary> Returns true if the sockets can be linked.</summary>
 /// <param name="socket01"> The first socket</param>
 /// <param name="socket02"> The second socket</param>
 /// <returns>True if the sockets can be linked.</returns>
 public bool CanBeLinked(Socket socket01, Socket socket02)
 {
     return socket02 != null && socket01 != null && socket01.Type == socket02.Type
            && socket01 != socket02 && socket01.Direction != socket02.Direction;
 }
Beispiel #11
0
 public void UnLink(Socket socket)
 {
     Socket socket2 = null;
     if (socket.Edge != null)
     {
         socket2 = socket.Edge.GetOtherSocket(socket);
     }
     UnLink(socket, socket2);
 }
 public override object GetResultOf(Socket outSocket)
 {
     return float.Parse(Number);
 }
 public override bool CanGetResultOf(Socket outSocket)
 {
     return AllInputSocketsConnected();
 }
        private void HandleDragAndDrop()
        {
            if (_currentCanvas == null) return;

            if (Event.current.type == EventType.MouseDown)
            {
                Socket target = _currentCanvas.GetSocketAt(Event.current.mousePosition);
                if (target != null && _currentDragSocket == null)
                {
                    if (target.Edge == null)
                    {
                        _currentDragSocket = target;
                    }
                    else
                    {
                        _currentDragSocket = target.Edge.GetOtherSocket(target);
                        _currentCanvas.Graph.UnLink(_currentDragSocket, target);
                    }
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                if (_currentDragSocket != null)
                {
                    Socket target = _currentCanvas.GetSocketAt(Event.current.mousePosition);
                    if (_currentCanvas.Graph.CanBeLinked(target, _currentDragSocket))
                    {
                        // drop edge event
                        if (target.Edge != null)
                        {
                            // replace edge
                            _currentCanvas.Graph.UnLink(target);
                        }

                        if (_currentDragSocket.Direction == SocketDirection.Input)
                        {
                            _currentCanvas.Graph.Link(_currentDragSocket, target);
                        }
                        else
                        {
                            _currentCanvas.Graph.Link(target, _currentDragSocket);
                        }

                        Event.current.Use();
                    }
                    _currentDragSocket = null;
                    Repaint();
                }
            }

            if (Event.current.type == EventType.MouseDrag)
            {
                if (_currentDragSocket != null) Event.current.Use();
            }
        }
Beispiel #15
0
 public void UnLink(Socket s01, Socket s02)
 {
     if (_listener != null && TriggerEvents)
     {
         _listener.OnUnLink(s01, s02);
     }
     if (s01 != null && s01.Edge != null)
     {
         s01.Edge.Input = null;
         s01.Edge.Output = null;
         s01.Edge = null;
     }
     if (s02 != null && s02.Edge != null)
     {
         s02.Edge.Input = null;
         s02.Edge.Output = null;
         s02.Edge = null;
     }
     if (_listener != null && TriggerEvents)
     {
         _listener.OnUnLinked(s01, s02);
     }
 }
 public void OnUnLink(Socket s01, Socket s02)
 {
     //Debug.Log("OnUnLink: Node " + s01.Edge.Output.Parent.Id + " from Node " + s02.Edge.Input.Parent.Id);
     UpdateNodes();
 }
Beispiel #17
0
 public abstract bool CanGetResultOf(Socket outSocket);
Beispiel #18
0
 /// <summary> Returns true if this node contains the assigned socket.</summary>
 /// <param name="socket"> The socket to use.</param>
 /// <returns>True if this node contains the assigned socket.</returns>
 public bool ContainsSocket(Socket socket)
 {
     return Sockets.Contains(socket);
 }
Beispiel #19
0
 public Socket GetOtherSocket(Socket socket)
 {
     if (socket == Input) return Output;
     else return Input;
 }
 private void DrawDragEdge(Socket currentDragingSocket)
 {
     if (currentDragingSocket != null)
     {
         _tmpVector01 = Edge.GetEdgePosition(currentDragingSocket, _tmpVector01);
         _tmpVector02 = Edge.GetTangentPosition(currentDragingSocket, _tmpVector01);
         Edge.DrawEdge(_tmpVector01, _tmpVector02, Event.current.mousePosition, Event.current.mousePosition,
             currentDragingSocket.Type);
     }
 }
 public void OnUnLinked(Socket s01, Socket s02)
 {
     //Debug.Log("OnUnLinked: Socket " + s02 + " and Socket " + s02);
     UpdateNodes();
 }
Beispiel #22
0
        public bool Link(Socket inputSocket, Socket sourceSocket)
        {
            if (!CanBeLinked(inputSocket, sourceSocket))
            {
                Debug.LogWarning("Sockets can not be linked.");
                return false;
            }

            if (inputSocket.Type == sourceSocket.Type)
            {
                Edge edge = new Edge(inputSocket, sourceSocket);
                inputSocket.Edge = edge;
                sourceSocket.Edge = edge;

                if (!AllowCicles && HasCicle())
                {
                    // revert
                    Debug.Log("Can not link sockets. Circles are not allowed.");
                    return false;
                }

                if (_listener != null && TriggerEvents)
                {
                    _listener.OnLink(edge);
                }
            }
            return true;
        }