Ejemplo n.º 1
0
        private Rect DrawNodeWindow(NodeContainer container)
        {
            //container.rect.x = container.rect.x < 0 ? 0 : container.rect.x;
            //container.rect.y = container.rect.y < 0 ? 0 : container.rect.y;
            container.rect = GUI.Window(container.winID, container.rect, (int id) => { DoNodeWindowGUI(container); }, "");

            if (container.hasOutput()) {
                GUI.DrawTexture(new Rect(container.rect.x - 14, container.rect.center.y - 9, 14, 18), texPort);
                GUI.Label(new Rect(container.rect.x - 14, container.rect.center.y - 9, 14, 18), "o");
            }
            for (int i = 0; i < container.getInputNum(); i++) {
                GUI.DrawTexture(container.getInputPortRect(i), texPort);
                GUI.Label(container.getInputPortRect(i), container.GetInputLabel(i));
            }

            return container.rect;
        }
Ejemplo n.º 2
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());
                }
            }
        }