Exemple #1
0
        internal Task CreateTask(BehaviorTree tree, BehaviorTreeDesc treeDesc, Task parentTask, uint taskId)
        {
            var descWrapper = treeDesc.FindTaskDesc(taskId);
            var desc        = descWrapper.CustomDesc;
            var task        = desc.CreateTask(tree, parentTask, descWrapper.Id);

            if (!(task is LeafTask))
            {
                if (task is DecoratorTask)
                {
                    var decoratorTask = (DecoratorTask)task;
                    var childTaskId   = ((DecoratorTaskDescWrapper)descWrapper).ChildTaskId;
                    var childTask     = CreateTask(tree, treeDesc, task, childTaskId);
                    decoratorTask.InitializeChild(childTask);
                }
                else
                {
                    var compositeTask = (CompositeTask)task;
                    var childTaskIds  = ((CompositeTaskDescWrapper)descWrapper).ChildTaskIds;
                    var childTasks    = childTaskIds.Select(i => CreateTask(tree, treeDesc, task, i)).ToArray();
                    compositeTask.InitializeChildren(childTasks);
                }
            }

            tree.InitializeTask(task);

            return(task);
        }
        public static byte[] SerializeDesc(BehaviorTreeDesc desc)
        {
            CheckInstanceInitialized();

            return(instance.SerializeDesc(desc));
        }
Exemple #3
0
 public BehaviorTree CreateTree(IBehaviorTreeOwner owner, BehaviorTreeDesc treeDesc, Task parentTask = null)
 {
     return(new BehaviorTree(this, owner, treeDesc, parentTask));
 }
Exemple #4
0
        internal BehaviorTree(BehaviorTreeManager treeManager, IBehaviorTreeOwner owner, BehaviorTreeDesc description, Task parentTask)
        {
            this.treeManager = treeManager;
            this.owner       = owner;
            this.parentTask  = parentTask;

            eventBus      = new EventBus(this);
            timerManager  = new TimerManager(this);
            taskScheduler = new TaskScheduler(this);

            rootTask = treeManager.CreateTask(this, description, parentTask, description.RootTaskId);
        }