コード例 #1
0
ファイル: NodeWindow.cs プロジェクト: kurtdog/DoubleTapp
        public NodeWindow(Node node)
        {
            this.windowIndex = indexCount;
            indexCount++;

            // cast to specific type
            if(node is GeneratorNode) {
            generatorNode = (GeneratorNode)node;
            type = WINDOWTYPE.GENERATOR;
            node.title = generatorNode.type.ToString();
            }
            if(node is OperatorNode){
            operatorNode = (OperatorNode)node;
            type = WINDOWTYPE.OPERATOR;
            node.title = operatorNode.type.ToString();
            }
            if(node is OutputNode) {
            outputNode = (OutputNode)node;
            type = WINDOWTYPE.OUTPUT;
            previewSize = PreviewSize.x2;
            }
            if(node is MacroNode) {
            macroNode = (MacroNode)node;
            type = WINDOWTYPE.MACRO;
            }
            if(node is TextureNode) {
            textureNode = (TextureNode)node;
            type = WINDOWTYPE.TEXTURE;
            }
            if(node is ColorNode) {
            colorNode = (ColorNode)node;

            gradient = new GradientWrapper();
            gradient.GradientData = colorNode.gradient;

            type = WINDOWTYPE.COLOR;
            }

            // also save general reference
            this.node = node;

            // random connection color
            connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

            UpdatePreview();
            node.rect.height = controlHeight + (int)previewSize;
            node.rect.width = (int)previewSize + 20;
            if(node.rect.width < 200)
            node.rect.width = 200;

            if(showOutputOptions)
            showOutputOptions = false;
        }
コード例 #2
0
ファイル: ModuleEditorWindow.cs プロジェクト: bbeaulieu/Unity
        private void ShowModuleViewGUI()
        {
            GUI.Label(new Rect(10, 50, 160, 20), "Create Nodes:");

            if (GUI.Button(new Rect(10, 70, 100, 20), "Generator"))
            {
                GeneratorNode g = new GeneratorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
                g.seed = Random.Range(-10000, 10000);
                settings.nodes.Add(g);
                windows.Add(new NodeWindow(g));
            }
            if (GUI.Button(new Rect(120, 70, 100, 20), "Operator"))
            {
                OperatorNode o = new OperatorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
                settings.nodes.Add(o);
                windows.Add(new NodeWindow(o));
            }
            if (GUI.Button(new Rect(230, 70, 100, 20), "Macro"))
            {
                MacroNode m = new MacroNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
                settings.nodes.Add(m);
                windows.Add(new NodeWindow(m));
            }
            if (GUI.Button(new Rect(380, 70, 100, 20), "Color Node"))
            {
                ColorNode c = new ColorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
                settings.nodes.Add(c);
                windows.Add(new NodeWindow(c));
            }
            if (GUI.Button(new Rect(490, 70, 100, 20), "Texture Output"))
            {
                TextureNode t = new TextureNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
                settings.nodes.Add(t);
                windows.Add(new NodeWindow(t));
            }

            scrollPos = GUI.BeginScrollView(new Rect(10, 95, this.position.width - 10, this.position.height - 105), scrollPos, scrollRect);

            BeginWindows();

            foreach (NodeWindow n in windows)
            {
                GUI.color = Color.white;

                // show the window
                Rect rect = n.Show();

                // delete button
                if (!(n.node is OutputNode))
                {
                    if (GUI.Button(new Rect(rect.x + rect.width - 20, rect.y - 16, 20, 16), "x"))
                    {
                        toBeRemoved.Add(n);
                    }
                }

                // input port buttons
                if (n.node.Inputs != null)
                {
                    for (int i = 0; i < n.node.Inputs.Length; i++)
                    {
                        Rect input = new Rect(rect.x - 14,
                                              (rect.y + rect.height / 2 - 7) + i * 20f - (n.node.Inputs.Length - 1) * 20f / 2,
                                              14,
                                              14);

                        if (!isConnecting)
                        {
                            if (GUI.Button(input, ""))
                            {
                                isConnecting = true;
                                isInput      = true;
                                selectedNode = n.node;
                                selectedPort = i;
                            }
                        }
                        else
                        {
                            if (!isInput)
                            {
                                if (GUI.Button(input, ""))
                                {
                                    n.node.Connect(selectedNode, i);
                                    n.UpdatePreview();
                                    isConnecting = false;
                                }
                            }
                        }
                        // draw connections
                        if (n.node.Inputs[i] != null)
                        {
                            DrawBezier(n.node.Inputs[i].Rect.ToRect(), input, n.connectionColor);
                        }
                    }
                }

                // output button
                if (n.node.HasOutput)
                {
                    Rect output = new Rect(rect.x + rect.width - 2,
                                           rect.y + rect.height / 2 - 7,
                                           14,
                                           14);

                    if (n.node.module != null)
                    {
                        if (n.node.module.colorOutput)
                        {
                            GUI.color = Color.green;
                        }
                        else
                        {
                            GUI.color = Color.white;
                        }
                    }

                    if (!isConnecting)
                    {
                        if (GUI.Button(output, ""))
                        {
                            isConnecting = true;
                            isInput      = false;
                            selectedNode = n.node;
                        }
                    }
                    else
                    {
                        if (isInput)
                        {
                            if (GUI.Button(output, ""))
                            {
                                selectedNode.Connect(n.node, selectedPort);
                                UpdateNodeWindow(selectedNode);
                                isConnecting = false;
                            }
                        }
                    }
                }
            }

            EndWindows();

            GUI.EndScrollView();
        }
コード例 #3
0
        private void ShowModuleViewGUI()
        {
            GUI.Label(new Rect(10, 50, 160, 20), "Create Nodes:");

            if(GUI.Button(new Rect(10, 70, 100, 20), "Generator")) {
            GeneratorNode g = new GeneratorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            g.seed = Random.Range(-10000, 10000);
            settings.nodes.Add(g);
            windows.Add(new NodeWindow(g));
            }
            if(GUI.Button(new Rect(120, 70, 100, 20), "Operator")) {
            OperatorNode o = new OperatorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            settings.nodes.Add(o);
            windows.Add(new NodeWindow(o));
            }
            if(GUI.Button(new Rect(230, 70, 100, 20), "Macro")) {
            MacroNode m = new MacroNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            settings.nodes.Add(m);
            windows.Add(new NodeWindow(m));
            }
            if(GUI.Button(new Rect(380, 70, 100, 20), "Color Node")) {
            ColorNode c = new ColorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            settings.nodes.Add(c);
            windows.Add(new NodeWindow(c));
            }
            if(GUI.Button(new Rect(490, 70, 100, 20), "Texture Output")) {
            TextureNode t = new TextureNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            settings.nodes.Add(t);
            windows.Add(new NodeWindow(t));
            }

            scrollPos = GUI.BeginScrollView(new Rect(10, 95, this.position.width -10, this.position.height - 105), scrollPos, scrollRect);

            BeginWindows();

            foreach(NodeWindow n in windows) {
            GUI.color = Color.white;

            // show the window
            Rect rect = n.Show();

            // delete button
            if(!(n.node is OutputNode)) {
                if(GUI.Button(new Rect(rect.x + rect.width - 20,rect.y - 16, 20, 16), "x")) {
                    toBeRemoved.Add(n);
                }
            }

            // input port buttons
            if(n.node.Inputs != null) {
                for(int i = 0; i < n.node.Inputs.Length; i++) {
                    Rect input = new Rect(rect.x - 14,
                                          (rect.y + rect.height / 2 - 7) + i * 20f - (n.node.Inputs.Length-1) * 20f / 2,
                                          14,
                                          14);

                    if(!isConnecting) {
                        if(GUI.Button(input, "")) {
                            isConnecting = true;
                            isInput = true;
                            selectedNode = n.node;
                            selectedPort = i;
                        }
                    }
                    else {
                        if(!isInput) {
                            if(GUI.Button(input, "")) {
                                n.node.Connect(selectedNode, i);
                                n.UpdatePreview();
                                isConnecting = false;
                            }
                        }
                    }
                    // draw connections
                    if(n.node.Inputs[i] != null)
                        DrawBezier(n.node.Inputs[i].Rect.ToRect(), input, n.connectionColor);
                }
            }

            // output button
            if(n.node.HasOutput) {
                Rect output = new Rect(rect.x + rect.width - 2,
                                       rect.y + rect.height / 2 - 7,
                                       14,
                                       14);

                if(n.node.module != null) {
                    if(n.node.module.colorOutput)
                        GUI.color = Color.green;
                    else
                        GUI.color = Color.white;
                }

                if(!isConnecting) {
                    if(GUI.Button(output, "")) {
                        isConnecting = true;
                        isInput = false;
                        selectedNode = n.node;
                    }
                }
                else {
                    if(isInput) {
                        if(GUI.Button(output, "")) {
                            selectedNode.Connect(n.node, selectedPort);
                            UpdateNodeWindow(selectedNode);
                            isConnecting = false;
                        }
                    }
                }
            }
            }

            EndWindows();

            GUI.EndScrollView();
        }
コード例 #4
0
ファイル: NodeWindow.cs プロジェクト: bbeaulieu/Unity
        public NodeWindow(Node node)
        {
            this.windowIndex = indexCount;
            indexCount++;

            // cast to specific type
            if (node is GeneratorNode)
            {
                generatorNode = (GeneratorNode)node;
                type          = WINDOWTYPE.GENERATOR;
                node.title    = generatorNode.type.ToString();
            }
            if (node is OperatorNode)
            {
                operatorNode = (OperatorNode)node;
                type         = WINDOWTYPE.OPERATOR;
                node.title   = operatorNode.type.ToString();
            }
            if (node is OutputNode)
            {
                outputNode  = (OutputNode)node;
                type        = WINDOWTYPE.OUTPUT;
                previewSize = PreviewSize.x2;
            }
            if (node is MacroNode)
            {
                macroNode = (MacroNode)node;
                type      = WINDOWTYPE.MACRO;
            }
            if (node is TextureNode)
            {
                textureNode = (TextureNode)node;
                type        = WINDOWTYPE.TEXTURE;
            }
            if (node is ColorNode)
            {
                colorNode = (ColorNode)node;

                if (colorNode.gradient == null)
                {
                    colorNode.gradient = new Gradient();
                    if (colorNode.gradientColorKeys != null)
                    {
                        colorNode.gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(colorNode.gradientColorKeys);
                        colorNode.gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(colorNode.gradientAlphaKeys);
                    }
                    gradient = new GradientWrapper();
                    gradient.GradientData = colorNode.gradient;
                }

                type = WINDOWTYPE.COLOR;
            }

            // also save general reference
            this.node = node;

            // random connection color
            connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

            UpdatePreview();
            node.rect.height = controlHeight + (int)previewSize;
            node.rect.width  = (int)previewSize + 20;
            if (node.rect.width < 200)
            {
                node.rect.width = 200;
            }
        }