Example #1
0
    void Start()
    {
        _flowAI = GetComponent <FlowAIHolder>().flowAI;

        proc1 = new ProcessNode();
        proc2 = new ProcessNode();
        proc3 = new ProcessNode();
        proc4 = new ProcessNode();
        proc5 = new ProcessNode();

        rand1 = new BranchNode();

        proc1.Initialize(1.0f, rand1, () => TFDebug.Log("visualizer", "proc1 finished"), "PROCESS1");
        proc2.Initialize(1.0f, proc3, () => TFDebug.Log("visualizer", "proc2 finished"), "PROCESS2");
        proc3.Initialize(1.0f, proc1, () => TFDebug.Log("visualizer", "proc3 finished"), "PROCESS3");
        proc4.Initialize(1.0f, proc5, () => TFDebug.Log("visualizer", "proc4 finished"), "PROCESS4");
        proc5.Initialize(1.0f, proc1, () => TFDebug.Log("visualizer", "proc5 finished"), "PROCESS5");

        rand1.Initialize(proc2, 1.0f, proc4, 1.0f, () =>
        {
            bool result = Random.Range(0, 2) == 0;
            TFDebug.Log("visualizer", "rand1 {0}", result.ToString());
            return(result);
        });

        rand1.summary = "RANDOM";

        _flowAI.AddNode(proc1, proc2, proc3, proc4, proc5, rand1);
        _flowAI.entryPointNode.nextNode = proc1;
        _flowAI.Entry();
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        //FlowAI生成 Create FlowAI.
        _flowAI = GetComponent <FlowAIHolder>().flowAI;

        //ノード生成 Create nodes.
        var foundBranch   = new BranchNode();
        var missingBranch = new  BranchNode();

        var foundBranch2   = new BranchNode();
        var missingBranch2 = new BranchNode();

        // 旋回
        var rotNode     = new ProcessNode();
        var stopRotNode = new ProcessNode();

        // 攻撃
        var ShootingNode     = new ProcessNode();
        var StopShootingNode = new ProcessNode();


        foundBranch.summary   = "見てる?";
        missingBranch.summary = "見てない";

        foundBranch2.summary   = "打てる?";
        missingBranch2.summary = "打てない";

        rotNode.summary     = "まわる";
        stopRotNode.summary = "回らない";

        ShootingNode.summary     = "打ちます";
        StopShootingNode.summary = "打つのやめます";


        //ノード初期化 Initialize nodes.
        rotNode.Initialize(0.1f, foundBranch, () => _isRot      = true);
        stopRotNode.Initialize(0.1f, ShootingNode, () => _isRot = false);

        ShootingNode.Initialize(0.1f, foundBranch2, () => _isBullet = true);
        StopShootingNode.Initialize(0.1f, rotNode, () => _isBullet  = false);

        foundBranch.Initialize(stopRotNode, 0.1f, rotNode, 0.1f, () => _isFound);
        missingBranch.Initialize(rotNode, 0.1f, stopRotNode, 0.1f, () => !_isFound);

        foundBranch2.Initialize(ShootingNode, 0.1f, StopShootingNode, 0.1f, () => _isFound);
        missingBranch2.Initialize(StopShootingNode, 0.1f, ShootingNode, 0.1f, () => !_isFound);

        //ノード追加 Add nodes at FlowAIBasis.
        _flowAI.AddNode(rotNode, foundBranch, missingBranch, stopRotNode, ShootingNode, StopShootingNode, foundBranch2, missingBranch2);

        //エントリポイントの次のノードを設定 Setting next node for entry point node.
        _flowAI.entryPointNode.nextNode = rotNode;

        //AI開始 Transition entry point.
        _flowAI.Entry();

        animator = GetComponent <Animator>();

        //animator.SetTrigger("Shot");
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        //FlowAI生成 Create FlowAI.
        _flowAI = GetComponent <FlowAIHolder>().flowAI;

        //ノード生成 Create nodes.
        var rotNode       = new ProcessNode();
        var foundBranch   = new BranchNode();
        var missingBranch = new BranchNode();

        var alertNode     = new ProcessNode();
        var stopAlertNode = new ProcessNode();
        var stopRotNode   = new ProcessNode();

        //ノード初期化 Initialize nodes.
        rotNode.Initialize(0.1f, foundBranch, () => _isRot       = true);
        stopRotNode.Initialize(0.1f, missingBranch, () => _isRot = false);

        foundBranch.Initialize(alertNode, 0.1f, foundBranch, 0.1f, () => _isFound);
        missingBranch.Initialize(stopAlertNode, 0.1f, missingBranch, 0.1f, () => !_isFound);

        alertNode.Initialize(0.1f, stopRotNode, () => Debug.Log("Alert!"));
        stopAlertNode.Initialize(0.1f, rotNode, () => Debug.Log("Alert stopped"));

        //ノード追加 Add nodes at FlowAIBasis.
        _flowAI.AddNode(rotNode, foundBranch, missingBranch, alertNode, stopAlertNode, stopRotNode);

        //エントリポイントの次のノードを設定 Setting next node for entry point node.
        _flowAI.entryPointNode.nextNode = rotNode;

        //AI開始 Transition entry point.
        _flowAI.Entry();
    }
Example #4
0
    public void BranchNodeTest()
    {
        float elapsed = 0f;

        var basis = new FlowAIBasis();

        var branch = new BranchNode();
        var proc1 = new ProcessNode();
        var proc2 = new ProcessNode();

        branch.Initialize(
            proc1, 0.2f,
            proc2, 0.2f,
            () =>
            {
                return elapsed < 0.5f;
            });

        proc1.Initialize(0.2f, branch, () => Debug.Log("プロセス1完了"));
        proc2.Initialize(0.2f, branch, () => Debug.Log("プロセス2完了"));

        basis.entryPointNode.nextNode = branch;
        basis.AddNode(branch, proc1, proc2);

        basis.Entry();

        for(int f1=0;f1<50;f1++)
        {
            elapsed += 0.1f;
            Debug.LogFormat("---{0:0.0}sec---", elapsed);
            basis.Update(0.1f);
        }
    }
Example #5
0
    BranchNode GetOrAddController(GameObject gameObject)
    {
        BranchNode branchController = gameObject.GetComponent <BranchNode>();

        if (branchController == null)
        {
            branchController = gameObject.AddComponent <BranchNode>();
            branchController.Initialize();
        }

        return(branchController);
    }
    // Use this for initialization
    void Start()
    {
        //FlowAI生成 Create FlowAI.
        Assert.AreNotEqual(GetComponent <FlowAIHolder>(), null);
        flowAI = GetComponent <FlowAIHolder>().flowAI;

        ProcessNode chaseNode         = new ProcessNode();
        ProcessNode explodeNode       = new ProcessNode();
        ProcessNode shootNode         = new ProcessNode();
        ProcessNode alertNode         = new ProcessNode();
        ProcessNode patrolMoveNode    = new ProcessNode();
        ProcessNode patrolReachedNode = new ProcessNode();

        BranchNode canSeePlayerNode         = new BranchNode();
        BranchNode playerInAttackRangeNode  = new BranchNode();
        BranchNode checkReachedWaypointNode = new BranchNode();
        BranchNode checkPlayerEscapedNode   = new BranchNode();

        canSeePlayerNode.Initialize(alertNode, 0.05f, checkReachedWaypointNode, 0.05f, CanSeePlayer, "Can See Player?");
        alertNode.Initialize(0.05f, playerInAttackRangeNode, AlertNodeFunction, "Alert Others");
        checkReachedWaypointNode.Initialize(patrolReachedNode, 0.05f, patrolMoveNode, 0.05f, CheckReachedWaypoint, "Reached Waypoint?");

        chaseNode.Initialize(0.05f, checkPlayerEscapedNode, ChaseNodeFunction, "Chase Target");
        checkPlayerEscapedNode.Initialize(canSeePlayerNode, 0.05f, playerInAttackRangeNode, 0.05f, CheckPlayerEscaped, "Has Target Escaped?");

        patrolMoveNode.Initialize(0.05f, canSeePlayerNode, PatrolMoveNodeFunction, "Patrol Move");
        patrolReachedNode.Initialize(0.05f, canSeePlayerNode, PatrolReachedNodeFunction, "Patrol Reached Waypoint");

        switch (attackType)
        {
        case AttackType.AttackType_Explode:
            explodeNode.Initialize(0.05f, null, ExplodeNodeFunction, "Explosion!");
            playerInAttackRangeNode.Initialize(explodeNode, 0.05f, chaseNode, 0.05f, PlayerInAttackRange, "Is Target In Explosion Range?");
            flowAI.AddNode(explodeNode);
            break;

        case AttackType.AttackType_Shoot:
            shootNode.Initialize(1.0f, playerInAttackRangeNode, ShootNodeFunction, "Shoot!");
            playerInAttackRangeNode.Initialize(shootNode, 0.05f, chaseNode, 0.05f, PlayerInAttackRange, "Is Target In Shooting Range?");
            flowAI.AddNode(shootNode);
            break;

        default:
            break;
        }


        flowAI.AddNode(alertNode, patrolMoveNode, patrolReachedNode, chaseNode, canSeePlayerNode, playerInAttackRangeNode, checkReachedWaypointNode, checkPlayerEscapedNode);

        //エントリポイントの次のノードを設定 Setting next node for entry point node.
        flowAI.entryPointNode.nextNode = canSeePlayerNode;

        //AI開始 Transition entry point.
        flowAI.Entry();

        chaseNodeId = chaseNode.localId;

        // Initialise events.
        InitEvents();

        chaseGiveUpTimer = chaseGiveUpDuration;
        visionCone.SetMaterial(patrolCannotSeePlayerMaterial);
        visionCone.CreateVisionConeObject(gameObject);
    }