예제 #1
0
 public void add_child_node(general_node child)
 {
     if (children == null)
     {
         Debug.Log("Error! Trying to add child to leaf node");
     }
     else
     children.Add(child);
 }
예제 #2
0
    // Construct a tree.
    private void InitiateNodes()
    {
        // fight branch
        in_range_check = new is_in_range(this);
        cooldown_check = new is_cooled_down(this);
        attack = new attack_leaf(this);
        attack_sequence = new sequence(this);
        attack_sequence.add_child_node(in_range_check);
        attack_sequence.add_child_node(cooldown_check);
        attack_sequence.add_child_node(attack);
        return_success = new always_success(this);
        return_success.add_child_node(attack_sequence);
        check_visible = new is_visible(this);
        lock_on = new lock_on_target_leaf(this);
        fight_sequence = new sequence(this);
        fight_sequence.add_child_node(check_visible);
        fight_sequence.add_child_node(lock_on);
        fight_sequence.add_child_node(return_success);

        // search branch
        go_to_spot = new search_leaf(this);
        look_around = new lookout_leaf(this);
        search_routine = new sequence_memory(this);
        search_routine.add_child_node(go_to_spot);
        search_routine.add_child_node(look_around);
        searching_check = new is_searching(this);
        search_sequence = new sequence(this);
        search_sequence.add_child_node(searching_check);
        search_sequence.add_child_node(search_routine);

        // idle
        idle = new idle_leaf(this);

        // root
        rootnode = new selector(this);
        rootnode.add_child_node(fight_sequence);
        rootnode.add_child_node(search_sequence);
        rootnode.add_child_node(idle);
    }