Esempio n. 1
0
    private void BuildBehaviourTree()
    {
        var chaseAction              = new ActionNode(Chase);
        var canChaseDecorator        = new DecoratorNode(chaseAction, () => remainingTimeToChase > 0.0f);
        var approachAction           = new ActionNode(ApproachToTarget);
        var canApproachDecorator     = new DecoratorNode(approachAction, () => isTargetInDetectionArea);
        var selector1                = new SelectorNode(canApproachDecorator, canChaseDecorator);
        var fireAction               = new ActionNode(Fire);
        var canFireDecorator         = new DecoratorNode(fireAction, () => { return(gun.CanFire()); });
        var faceToTargetAction       = new ActionNode(FaceToTarget);
        var selector2                = new SelectorNode(canFireDecorator, faceToTargetAction);
        var canSeeTargetDecorator    = new DecoratorNode(selector2, CanSeeTarget);
        var selector3                = new SelectorNode(canSeeTargetDecorator, approachAction);
        var isTargetInRangeDecorator = new DecoratorNode(selector3, () => isTargetInRange);
        var selector4                = new SelectorNode(isTargetInRangeDecorator, selector1);
        var isTargetNullDecorator    = new DecoratorNode(selector4, () => { return(target != null); });
        var waitAction               = new ActionNode(Wait);
        var selector5                = new SelectorNode(isTargetNullDecorator, waitAction);
        var blownChecker             = new DecoratorNode(waitAction, () => { return(core.isBlown); });
        var selector6                = new SelectorNode(blownChecker, selector5);

        behaviourTree = new BehaviourTree(selector6);
    }