Ejemplo n.º 1
0
        public void LoadXML(string xml)
        {
            if (rootNode == null && (rootNode = nodes.Find((Node n) => n.GetID == EditorAIRootNode.ID) as EditorAIRootNode) == null)
            {
                rootNode = Node.Create(EditorAIRootNode.ID, Vector2.zero, this) as EditorAIRootNode;
            }

            Debug.Log("Loading");

            XmlSerializer ser = new XmlSerializer(typeof(AINode), nodeTypes);
            StringReader  sr  = new StringReader(xml);

            try
            {
                object o = ser.Deserialize(sr);
                if (o is AINode)
                {
                    EditorAINode editorNode = LoadNode(o as AINode);
                    editorNode.Parent.ApplyConnection(rootNode.child);

                    LayoutNodes(rootNode, 0, 10, 0, 100);
                    AdjustLayout(rootNode, -rootNode.position);

                    Debug.Log("Done");
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            sr.Close();
        }
Ejemplo n.º 2
0
        public float LayoutNodes(EditorAINode node, float alignment, float padding, float verticalPosition, float verticalPadding)
        {
            float halfPadding        = padding / 2;
            float halfVerticalPading = verticalPadding / 2;

            if (node is EditorAICombinationalNode || node is EditorAIDecoratorNode || node is EditorAIRootNode)
            {
                float startAlign = alignment;
                foreach (var child in node.GetChildren())
                {
                    if (child == null)
                    {
                        continue;
                    }
                    alignment = LayoutNodes(child, alignment, padding, verticalPosition + node.size.y + verticalPadding, verticalPadding);
                }
                node.position = new Vector2((startAlign + alignment) / 2, (verticalPosition + halfVerticalPading)) + Vector2.left * (node.size.x / 2);
                return(alignment);
            }
            else
            {
                node.position = Vector2.zero + Vector2.right * (alignment + halfPadding) + Vector2.up * (verticalPosition + halfVerticalPading);
                return(alignment + node.size.x + padding);
            }
        }
Ejemplo n.º 3
0
 public void AdjustLayout(EditorAINode node, Vector2 offset)
 {
     node.position += offset;
     foreach (var child in node.GetChildren())
     {
         AdjustLayout(child, offset);
     }
 }
        public override AINode GetTreeNode()
        {
            Decorator output = base.GetTreeNode() as Decorator;

            if (child.connected())
            {
                EditorAINode node = child.connection(0).body as EditorAINode;
                output.subNode = node.GetTreeNode();
            }

            return(output);
        }
Ejemplo n.º 5
0
     public override IEnumerable <EditorAINode> GetChildren()
     {
         if (child.connected())
         {
             EditorAINode node = child.connection(0).body as EditorAINode;
             if (node != null)
             {
                 return new EditorAINode[] { node }
             }
             ;
         }
         return(new EditorAINode[] { });
     }
 }
Ejemplo n.º 6
0
        public override AINode GetTreeNode()
        {
            var           output   = base.GetTreeNode();
            Combinational combNode = output as Combinational;

            foreach (var childConnection in dynamicConnectionPorts.Where(x => x.direction == Direction.Out))
            {
                if (!childConnection.connected())
                {
                    continue;
                }
                EditorAINode graphNode = childConnection.connection(0).body as EditorAINode;
                combNode.subNodes.Add(graphNode.GetTreeNode());
            }
            return(output);
        }
Ejemplo n.º 7
0
        public override IEnumerable <EditorAINode> GetChildren()
        {
            List <EditorAINode> output = new List <EditorAINode>();

            foreach (var childConnection in dynamicConnectionPorts.Where(x => x.direction == Direction.Out))
            {
                if (!childConnection.connected())
                {
                    continue;
                }
                EditorAINode graphNode = childConnection.connection(0).body as EditorAINode;
                if (graphNode != null)
                {
                    output.Add(graphNode);
                }
            }
            return(output);
        }
Ejemplo n.º 8
0
        public EditorAINode LoadDecorator(Decorator node)
        {
            EditorAIDecoratorNode output = Node.Create(EditorAIDecoratorNode.ID, Vector3.zero) as EditorAIDecoratorNode;

            output.dataType = node.GetType().ToString();
            var clone = node.Clone() as Decorator;

            clone.subNode = null;
            output.data   = new GenericSerializable(output.dataType);
            output.data.SetObject(clone, nodeTypes);

            //load child
            EditorAINode child = LoadNode(node.subNode);

            //attach children
            child.Parent.ApplyConnection(output.child);

            return(output);
        }
Ejemplo n.º 9
0
        public void PushChild(EditorAINode node)
        {
            ConnectionPort knob;

            if (dynamicConnectionPorts.Count == 0)
            {
                knob = CreateConnectionKnob(new ConnectionKnobAttribute("Child_" + (dynamicConnectionPorts.Count), Direction.Out, ConnectionCount.Single, NodeSide.Bottom));
                node.Parent.ApplyConnection(knob);
                return;
            }

            knob = dynamicConnectionPorts[dynamicConnectionPorts.Count - 1];
            if (knob.connected())
            {
                knob = CreateConnectionKnob(new ConnectionKnobAttribute("Child_" + (dynamicConnectionPorts.Count), Direction.Out, ConnectionCount.Single, NodeSide.Bottom));
                node.Parent.ApplyConnection(knob);
                return;
            }
            else
            {
                node.Parent.ApplyConnection(knob);
            }
        }
Ejemplo n.º 10
0
        public EditorAINode LoadCombinational(Combinational node)
        {
            EditorAICombinationalNode output = Node.Create(EditorAICombinationalNode.ID, Vector3.zero) as EditorAICombinationalNode;

            output.dataType = node.GetType().ToString();
            var clone = node.Clone() as Combinational;

            clone.subNodes = new List <AINode>();

            output.data = new GenericSerializable(output.dataType);
            output.data.SetObject(clone, nodeTypes);

            //load children
            foreach (var child in node.subNodes)
            {
                //load
                EditorAINode childNode = LoadNode(child);
                //attach
                output.PushChild(childNode);
            }

            return(output);
        }