A behaviour tree leaf node for running an action.
Наследование: IBehaviourTreeNode
        /// <summary>
        /// Create an action node.
        /// </summary>
        public BehaviourTreeBuilder Do(string name, Func<TimeData, BehaviourTreeStatus> fn)
        {
            if (parentNodeStack.Count <= 0)
            {
                throw new ApplicationException("Can't create an unnested ActionNode, it must be a leaf node.");
            }

            var actionNode = new ActionNode(name, fn);
            parentNodeStack.Peek().AddChild(actionNode);
            return this;
        }
        public void can_run_action()
        {
            var time = new TimeData();

            var invokeCount = 0;
            var testObject =
                new ActionNode(
                    "some-action",
                    t =>
                    {
                        Assert.Equal(time, t);

                        ++invokeCount;
                        return BehaviourTreeStatus.Running;
                    }
                );

            Assert.Equal(BehaviourTreeStatus.Running, testObject.Tick(time));
            Assert.Equal(1, invokeCount);
        }
Пример #3
0
        /// <summary>
        /// Create an action node.
        /// </summary>
        public BehaviourTreeBuilder <T> Do(string name, Func <T, Status> fn, bool isCondition = false)
        {
            if (_parentNodeStack.Count <= 0)
            {
                throw new ApplicationException("Can't create an unnested ActionNode, it must be a leaf node.");
            }
            if (string.IsNullOrEmpty(name))
            {
                name = fn.Method.Name;
            }

            int id         = ++_idCounter;
            var actionNode = new ActionNode <T>(name, id, fn)
            {
                IsDisabled  = IsBlacklisted(id),
                IsCondition = isCondition
            };

            _parentNodeStack.Peek().AddChild(actionNode);

            return(this);
        }