예제 #1
0
        public void AddNode(BaseNode node)
        {
            if (node.Graph != this)
                throw new Exception("Node's parent graph is not this graph.");

            if (!this.nodes.Contains(node))
            {
                this.nodes.Add(node);

                if (node is Output)
                {
                    this.outputs.Add((Output)node);
                }
            }
        }
 public GraphNode(Vector2 position, BaseNode node)
 {
     this.Position = position;
     this.node = node;
     // get all the inputs and outputs for display later.
     this.nodeOutputs = this.node.GetOuputNames();
     this.nodeInputs = this.node.GetInputNames();
     // set up the output preview texture array.
     if (this.node is Output)// doesn't have a normal output
         this.previewTextures = new Texture2D[1];
     else
         this.previewTextures = new Texture2D[nodeOutputs.Length];
     this.container = new TitledPanel(node.GetType().Name, new Rectangle(0, 0, 100, 130));
     this.container.Color = defaultColor;
     this.Linked = false;
     this.AddChild(container);
 }
예제 #3
0
        public void RemoveNode(BaseNode node)
        {
            if (node.Graph != this)
                throw new Exception("Node's parent graph is not this graph.");

            if (this.nodes.Contains(node))
            {
                this.nodes.Remove(node);

                if (node is Output)
                {
                    // only has inputs we dont care about clearing those up because the node isnt part of the graph anymore, and shouldnt be used.
                    this.outputs.Remove((Output)node);
                }
                else // remove all input references from remaining nodes.
                {
                    foreach (BaseNode n in this.nodes)
                    {
                        for (int i = 0; i < n.GetInputCount(); i++)
                        {
                            if (n.GetInput(i).Target == node)
                            {
                                string name = n.GetInputName(i);
                                n.SetInput(name, null);
                            }
                        }
                    }
                }
            }
        }