コード例 #1
0
    private static Node CreateInteractionBehavior(Dorf d, IInteractable i)
    {
        Condition findWork = new Condition(() => {
            //TODO: what check here? Maybe an action to get a work-place?
            return false;
        });

        BehaviorTrees.Action goToWork = new BehaviorTrees.Action(() => {
            //TODO: replace vector param with location of workplace!
            var mc = new MoveCommand(d,new Vector3(),WALKSPEED);
            if (mc.isAllowed()) {
                mc.execute();
                return Node.Status.RUNNING;
            } else {
                return Node.Status.FAIL;
            }
        });

        BehaviorTrees.Action work = new BehaviorTrees.Action(() => {
            //TODO: replace null value with some kind of interactable variable from d.
            var ic = new InteractCommand(d,null);
            if (ic.isAllowed()) {
                ic.execute();
                return Node.Status.RUNNING;
            } else {
                return Node.Status.FAIL;
            }
        });

        SequenceSelector root = new SequenceSelector(findWork,goToWork,work);
        return root;
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        mate = buddy.transform;
        speed = 1.1f;
        direction = mate.position - transform.position;

        root = new SequenceSelector(); redSeq = new SequenceSelector();
        colors = new PrioritySelector(); movement = new PrioritySelector();
        close = new Condition(() => Mathf.Abs(Vector3.Distance(transform.position, mate.position)) < kindaClose);
        red = new Action(Red); green = new Action(Green);
        toward = new Action(Toward); away = new Action(Away);

        root.AddChild(colors, movement);

        colors.AddChild(redSeq,1.0); colors.AddChild(green);
        redSeq.AddChild(close,red);

        movement.AddChild(away,farAway);
        towardPrio = movement.AddChild(toward);
        toward.name = "toward";
    }