Ejemplo n.º 1
0
        public static void Serialize(this Node root, BehaviorTreeConfig config)
        {
            config.Clear();
            BehaviorNodeConfig         rootNp = config.AddRootNode(root.GetType().Name);
            Queue <Node>               queue  = new Queue <Node>();
            Queue <BehaviorNodeConfig> npQue  = new Queue <BehaviorNodeConfig>();

            rootNp.describe = root.Description;
            queue.Enqueue(root);
            npQue.Enqueue(rootNp);
            while (queue.Count > 0)
            {
                Node cur = queue.Dequeue();
                BehaviorNodeConfig np = npQue.Dequeue();
                foreach (Node child in cur.GetChildren)
                {
                    BehaviorNodeConfig childNp = GetNodeConfigFromNode(child);
                    queue.Enqueue(child);
                    npQue.Enqueue(childNp);
                    config.AddChild(np, childNp);
                }
            }
            //             PrintNode(root);
            //             PrintConfigNode(config.RootNodeConfig);
        }
        public static BehaviourTreeNodeProxy <T> AddNodeToLast <T>(BehaviorTreeConfig tree) where T : Node
        {
            BehaviorNodeConfig         parent = tree.RootNodeConfig;
            string                     name   = typeof(T).Name;
            BehaviorNodeConfig         p      = tree.AddChild(parent, name);
            BehaviourTreeNodeProxy <T> proxy  = new BehaviourTreeNodeProxy <T>(p.ToNodeProto());

            return(proxy);
        }