Example #1
0
    void Awake()
    {
        // VisionCone生成
        _visionCone.CreateVisionConeObject(gameObject);
        //_visionCone.set

        // イベント初期化呼び出し
        InitEvents();
    }
    // 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);
    }