Ejemplo n.º 1
0
        void MyDragLine()
        {
            if (startLineNode != null) {
                if (bDragingInputLine) {
                    Vector2 lineEnd = startLineNode.getInputPortRect(startLinePort).center;
                    drawBezier(Event.current.mousePosition, lineEnd, new Color(0.8f, 0.8f, 0.8f), true);
                }
                else if (bDragingOutputLine) {
                    Vector2 lineStart = startLineNode.getOutputPortRect().center;
                    drawBezier(lineStart, Event.current.mousePosition, new Color(0.8f, 0.8f, 0.8f), true);
                }
            }

            foreach(var n in nodeContainers){
                for (int i = 0; i < n.getInputNum(); i++) {
                    var inputNode = n.node.inputs[i];
                    if (inputNode != null) {
                        var endPos = n.getInputPortRect(i).center;
                        var startPos = inputNode.container.getOutputPortRect().center;
                        drawBezier(startPos, endPos, new Color(0.8f, 0.8f, 0.8f), true);
                    }
                }
            }

            if (Event.current.type == EventType.MouseDrag) {
                if (bDragingInputLine) {

                }
            }
            if (Event.current.type == EventType.MouseDown) {
                if (Event.current.button == 0) {
                    foreach(var n in nodeContainers){
                        for (int i = 0; i < n.getInputNum(); i++) {
                            if (n.getInputPortRect(i).Contains(Event.current.mousePosition)) {
                                if (n.node.inputs[i] != null) {
                                    bDragingOutputLine = true;
                                    startLineNode = n.node.inputs[i].container;
                                    n.node.inputs[i] = null;
                                }
                                else {
                                    bDragingInputLine = true;
                                    startLineNode = n;
                                    startLinePort = i;
                                }
                            }
                        }
                        if (n.hasOutput()) {
                            if (n.getOutputPortRect().Contains(Event.current.mousePosition)) {
                                bDragingOutputLine = true;
                                startLineNode = n;
                            }
                        }
                    }
                }
            }
            if (Event.current.type == EventType.MouseUp) {
                if (Event.current.button == 0) {
                    if (bDragingInputLine) {
                        foreach(var n in nodeContainers){
                            if (n != startLineNode) {
                                if (n.hasOutput() && n.getOutputPortRect().Contains(Event.current.mousePosition)) {
                                    startLineNode.node.inputs[startLinePort] = n.node;
                                }
                            }
                        }
                    }
                    else if (bDragingOutputLine) {
                        foreach(var n in nodeContainers){
                            if (n != startLineNode) {
                                for (int i = 0; i < n.getInputNum(); i++) {
                                    if (n.getInputPortRect(i).Contains(Event.current.mousePosition)) {
                                        n.node.inputs[i] = startLineNode.node;
                                    }
                                }
                            }
                        }
                    }
                    bDragingInputLine = false;
                    bDragingOutputLine = false;
                    this.Repaint();

                    EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                }
            }
        }