コード例 #1
0
        public void can_create_parallel()
        {
            Init();

            var invokeCount = 0;

            var parallel = testObject
                           .Parallel("some-parallel", 2, 2)
                           .Do("some-action-1", t =>
            {
                ++invokeCount;
                return(Status.Success);
            })
                           .Do("some-action-2", t =>
            {
                ++invokeCount;
                return(Status.Success);
            })
                           .End()
                           .Build();

            Assert.IsType <ParallelNode <TimeData> >(parallel);
            Assert.Equal(Status.Success, parallel.Tick(new TimeData(0)));
            Assert.Equal(2, invokeCount);
        }
コード例 #2
0
        public void disabled_parent_nodes_is_ignored()
        {
            TimeData data        = new TimeData(0);
            var      invokeCount = 0;

            var builder = new BehaviourTreeBuilder <TimeData>(new List <int>
            {
                0,
                2,
                4
            });

            builder
            .Sequence("seq1")
            .Do("do1", t =>
            {
                ++invokeCount;
                throw new Exception("do1 invoked.");
            })
            .End()
            .Build()
            .Tick(data);

            builder
            .Selector("sel1")
            .Do("do2", t =>
            {
                ++invokeCount;
                throw new Exception("do2 invoked.");
            })
            .End()
            .Build()
            .Tick(data);

            builder
            .Parallel("para1", 0, 0)
            .Do("do3", t =>
            {
                ++invokeCount;
                throw new Exception("do3 invoked.");
            })
            .End()
            .Build()
            .Tick(data);
        }
コード例 #3
0
    private void Start()
    {
        var builder = new BehaviourTreeBuilder();

        //if Dist < 0.5 doA else doB
        tree = builder.
               Parallel("All", 20, 20).
               Do("RoateX", t => {
            transform.GetChild(0).Rotate(new Vector3(60, 0) * Time.deltaTime);
            return(BehaviourTreeStatus.Success);
        }).
               Do("RoateZ", t => {
            transform.GetChild(0).Rotate(new Vector3(0, 0, 60) * Time.deltaTime);
            return(BehaviourTreeStatus.Success);
        }).
               Selector("Find Target").
               Sequence("At Target").
               Condition("At Target", t => {
            Debug.Log("Is At Target");
            var dist = Vector3.Distance(transform.position, target.position);
            return(dist < 0.5f);
        }).
               Do("Idle", t => {
            Debug.Log("Idle");
            return(BehaviourTreeStatus.Success);
        }).
               End().
               Do("Go to Target", t =>
        {
            Debug.Log("Go to target");
            var dist            = Vector3.Distance(transform.position, target.position);
            transform.position += (target.position - transform.position).normalized * speed * Time.deltaTime;
            return(BehaviourTreeStatus.Success);
        }).
               End().
               End().
               Build();
    }