Ejemplo n.º 1
0
    // Use this for initialization
    public void Start()
    {
        inputData.attribute = GetComponent <CharacterAttribute>();

        rootNode.nodeName += "根";

        //条件
        var hasNoTarget = new PreconditionNOT(() => { return(inputData.attribute.hasTarget); });

        hasNoTarget.nodeName = "无目标";
        var hasTarget = new Precondition(hasNoTarget);

        hasTarget.nodeName = "发现目标";
        var isAnger = new Precondition(() => { return(inputData.attribute.isAnger); });

        isAnger.nodeName = "愤怒状态";
        var isNotAnger = new PreconditionNOT(isAnger);

        isNotAnger.nodeName = "非愤怒状态";
        var HPLessThan500 = new Precondition(() => { return(inputData.attribute.health < 500); });

        HPLessThan500.nodeName = "血少于500";
        var HPMoreThan500 = new PreconditionNOT(HPLessThan500);

        HPMoreThan500.nodeName = "血大于500";
        var isAlert = new Precondition(() => { return(inputData.attribute.isAlert); });

        isAlert.nodeName = "警戒";
        var isNotAlert = new PreconditionNOT(isAlert);

        isNotAlert.nodeName = "非警戒";


        var patrolNode = new SequenceNode();

        patrolNode.nodeName += "巡逻";
        patrolNode.AddCondition(hasNoTarget);
        patrolNode.AddCondition(isNotAlert);
        patrolNode.AddNode(new PatrolAction());

        var alert = new SequenceNode();

        alert.nodeName += "警戒";
        alert.AddCondition(hasNoTarget);
        alert.AddCondition(isAlert);
        alert.AddNode(new AlertAction());

        var runaway = new SequenceNode();

        runaway.nodeName += "逃跑";
        runaway.AddCondition(hasTarget);
        runaway.AddCondition(HPLessThan500);
        runaway.AddNode(new RunAwayAction());

        var attack = new SelectorNode();

        attack.nodeName += "攻击";
        attack.AddCondition(hasTarget);
        attack.AddCondition(HPMoreThan500);

        var attackCrazy = new SequenceNode();

        attackCrazy.nodeName += "疯狂攻击";
        attackCrazy.AddCondition(isAnger);
        attackCrazy.AddNode(new CrazyAttackAction());
        attack.AddNode(attackCrazy);

        var attackNormal = new SequenceNode();

        attackNormal.nodeName += "普通攻击";
        attackNormal.AddCondition(isNotAnger);
        attackNormal.AddNode(new AttackAction());
        attack.AddNode(attackNormal);

        rootNode.AddNode(patrolNode);
        rootNode.AddNode(alert);
        rootNode.AddNode(runaway);
        rootNode.AddNode(attack);
        var ret = rootNode.Enter(inputData);

        if (!ret)
        {
            Debug.Log("无可执行节点!");
        }
    }