Пример #1
0
        public NodeState Tick <TNodeBlob, TBlackboard>(int index, ref TNodeBlob blob, ref TBlackboard bb)
            where TNodeBlob : struct, INodeBlob
            where TBlackboard : struct, IBlackboard
        {
            NodeState flags      = 0;
            var       endIndex   = blob.GetEndIndex(index);
            var       childIndex = index + 1;

            while (childIndex < endIndex)
            {
                var prevState = blob.GetState(childIndex);
                flags     |= prevState.IsCompleted() ? 0 : VirtualMachine.Tick(childIndex, ref blob, ref bb);
                childIndex = blob.GetEndIndex(childIndex);
            }

            // var flags = blob.TickChildren(index, blackboard)
            //     .Aggregate((NodeState)0, (childStateFlags, childState) => {
            //         childStateFlags |= childState;
            //         return childStateFlags;
            //     });

            if (flags.HasFlagFast(NodeState.Running))
            {
                return(NodeState.Running);
            }
            if (flags.HasFlagFast(NodeState.Failure))
            {
                return(NodeState.Failure);
            }
            if (flags.HasFlagFast(NodeState.Success))
            {
                return(NodeState.Success);
            }
            return(0);
        }
Пример #2
0
        public NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard)
        {
            var childState = blob.TickChildren(index, blackboard).FirstOrDefault();

            if (childState == 0)
            {
                blob.ResetChildren(index, blackboard);
                childState = blob.TickChildren(index, blackboard).FirstOrDefault();
            }
            return(BreakStates.HasFlagFast(childState) ? childState : NodeState.Running);
        }
Пример #3
0
        public NodeState Tick <TNodeBlob, TBlackboard>(int index, ref TNodeBlob blob, ref TBlackboard blackboard)
            where TNodeBlob : struct, INodeBlob
            where TBlackboard : struct, IBlackboard
        {
            var childState = index.TickChildrenReturnFirstOrDefault(ref blob, ref blackboard);

            if (childState == 0)
            {
                index.ResetChildren(ref blob, ref blackboard);
                childState = index.TickChildrenReturnFirstOrDefault(ref blob, ref blackboard);
            }
            return(BreakStates.HasFlagFast(childState) ? childState : NodeState.Running);
        }
Пример #4
0
        public NodeState Tick <TNodeBlob, TBlackboard>(int index, ref TNodeBlob blob, ref TBlackboard bb)
            where TNodeBlob : struct, INodeBlob
            where TBlackboard : struct, IBlackboard
        {
            var countdown = CountdownSeconds.Read(index, ref blob, ref bb);

            if (countdown <= 0f)
            {
                return(0);
            }

            var childState = index.TickChild(ref blob, ref bb);

            if (BreakReturnState.HasFlagFast(childState))
            {
                return(childState);
            }

            countdown -= bb.GetData <BehaviorTreeTickDeltaTime>().Value;
            CountdownSeconds.Write(index, ref blob, ref bb, countdown);
            return(countdown <= 0f ? NodeState.Success : NodeState.Running);
        }