Example #1
0
        private static void BuildRecursive(BehaviourTreeBuilder builder, BehaviourTreeData data)
        {
            if (!Mapping.ContainsKey(data.Type))
            {
                throw new Exception($"Unknown node type {data.Type}");
            }

            var node   = CreateNodeByType(Mapping[data.Type], data.Properties);
            var parent = node as IBehaviourTreeNodeParent;

            if (parent != null)
            {
                builder.AddParent(parent);
            }
            else
            {
                builder.AddChild(node);
            }

            foreach (var childData in data.Children)
            {
                BuildRecursive(builder, childData);
            }

            if (parent != null)
            {
                builder.End();
            }
        }