Пример #1
0
        public BehaviorTreeBuilder <T> Decorator(Decorator <T> task)
        {
            if (this.CurrentParent == TaskId.Invalid)
            {
                throw new BehaviorTreeBuilderException("No Root node defined yet, add a branch first");
            }

            BranchTask <T> parent = (BranchTask <T>) this.stream.Get(this.CurrentParent);

            parent.AddChild(this.stream.Add(task));

            if (task.ChildCount <= 0)
            {
                // This decorator has no child yet, wait for a fluent set of a leaf node
                this.CurrentDecorator = task.Id;
            }

            this.CurrentLeaf = TaskId.Invalid;
            return(this);
        }
Пример #2
0
        public BehaviorTreeBuilder <T> Branch(BranchTask <T> task)
        {
            this.CurrentParent = this.stream.Add(task);

            if (this.CurrentDecorator != TaskId.Invalid)
            {
                // Decorate the branch and close the decorator out
                Decorator <T> decorator = (Decorator <T>) this.stream.Get(this.CurrentDecorator);
                decorator.AddChild(this.CurrentParent);

                this.CurrentDecorator = TaskId.Invalid;
            }
            else if (this.parentStack.Count > 0)
            {
                // Add as a sub-branch
                BranchTask <T> parent = (BranchTask <T>) this.stream.Get(this.parentStack.Peek());
                parent.AddChild(this.CurrentParent);
            }

            this.parentStack.Push(this.CurrentParent);
            this.CurrentLeaf = TaskId.Invalid;
            return(this);
        }
Пример #3
0
        public BehaviorTreeBuilder <T> Leaf(LeafTask <T> task)
        {
            if (this.CurrentDecorator != TaskId.Invalid)
            {
                Decorator <T> decorator = (Decorator <T>) this.stream.Get(this.CurrentDecorator);
                decorator.AddChild(this.stream.Add(task));

                this.CurrentDecorator = TaskId.Invalid;
                this.CurrentLeaf      = task.Id;
                return(this);
            }

            if (this.CurrentParent == TaskId.Invalid)
            {
                throw new BehaviorTreeBuilderException("No Root node defined yet, add a branch first");
            }

            BranchTask <T> parent = (BranchTask <T>) this.stream.Get(this.CurrentParent);

            parent.AddChild(this.stream.Add(task));

            this.CurrentLeaf = task.Id;
            return(this);
        }