コード例 #1
0
    // Use this for initialization
    void Start()
    {
        // 决策初始化
        IdleEnter      = ShieldMan.IdleEnter;
        IdleExit       = ShieldMan.IdleExit;
        IdleFeedbacker = ShieldMan.IdleFeedbacker;
        IdleActioner   = ShieldMan.IdleAction;

        ApproachEnter      = ShieldMan.ApproachEnter;
        ApproachExit       = ShieldMan.ApproachExit;
        ApproachFeedbacker = ShieldMan.ApproachFeedbacker;
        ApproachActioner   = ShieldMan.ApproachAction;

        AttackEnter      = ShieldMan.AttackEnter;
        AttackExit       = ShieldMan.AttackExit;
        AttackFeedbacker = ShieldMan.AttackFeedbacker;
        AttackActioner   = ShieldMan.AttackAction;

        EscapeEnter      = ShieldMan.EscapeEnter;
        EscapeExit       = ShieldMan.EscapeExit;
        EscapeFeedbacker = ShieldMan.EscapeFeedbacker;
        EscapeActioner   = ShieldMan.EscapeAction;

        BlockEnter      = ShieldMan.BlockEnter;
        BlockExit       = ShieldMan.BlockExit;
        BlockFeedbacker = ShieldMan.BlockFeedbacker;
        BlockActioner   = ShieldMan.BlockAction;

        DeathEnter      = ShieldMan.DeathEnter;
        DeathExit       = ShieldMan.DeathExit;
        DeathFeedbacker = ShieldMan.DeathFeedbacker;
        DeathActioner   = ShieldMan.DeathAction;

        // 动画
        idleAnim        = ShieldMan.SM_idle_Anim;
        walkAnim        = ShieldMan.SM_walk_Anim;
        runAnim         = ShieldMan.SM_run_Anim;
        shieldWalkAnim  = ShieldMan.SM_shield_walk_Anim;
        shieldWalkBAnim = ShieldMan.SM_shield_walkB_Anim;
        shieldStopAnim  = ShieldMan.SM_shield_stop_Anim;
        dieAnim         = ShieldMan.SM_die_Anim;
        hookAnim        = ShieldMan.SM_hook_Anim;
        chargeAnim      = ShieldMan.SM_charge_Anim;
        attackAnim      = ShieldMan.SM_attack_Anim;
        viglianceAnim   = ShieldMan.SM_vigilance_Anim;

        mRecorder = ShieldMan.SM_Recorder;

        // 节点
        roundEnter     = ShieldMan.SM_Round_Enter;
        roundState     = ShieldMan.SM_Round;
        roundExit      = ShieldMan.SM_Round_Exit;
        restEnter      = ShieldMan.SM_Rest_Enter;
        restState      = ShieldMan.SM_Rest;
        restExit       = ShieldMan.SM_Rest_Exit;
        vigilanceEnter = ShieldMan.SM_Vigilance_Enter;
        vigilanceState = ShieldMan.SM_Vigilance;
        vigilanceExit  = ShieldMan.SM_Vigilance_Exit;
        searchEnter    = ShieldMan.SM_Search_Enter;
        searchState    = ShieldMan.SM_Search;
        searchExit     = ShieldMan.SM_Search_Exit;

        chargeEnter   = ShieldMan.SM_Charge_Enter;
        chargeState   = ShieldMan.SM_Charge;
        chargeExit    = ShieldMan.SM_Charge_Exit;
        hookEnter     = ShieldMan.SM_Hook_Enter;
        hookState     = ShieldMan.SM_Hook;
        hookExit      = ShieldMan.SM_Hook_Exit;
        attackEnter   = ShieldMan.SM_Attack_Enter;
        attackState   = ShieldMan.SM_Attack;
        attackExit    = ShieldMan.SM_Attack_Exit;
        runawayEnter  = ShieldMan.SM_Runaway_Enter;
        runawayState  = ShieldMan.SM_Runaway;
        runawayExit   = ShieldMan.SM_Runaway_Exit;
        walkawayEnter = ShieldMan.SM_Walkaway_Enter;
        walkawayState = ShieldMan.SM_Walkaway;
        walkawayExit  = ShieldMan.SM_Walkaway_Exit;
        chaseEnter    = ShieldMan.SM_Chase_Enter;
        chaseState    = ShieldMan.SM_Chase;
        chaseExit     = ShieldMan.SM_Chase_Exit;
        shieldFEnter  = ShieldMan.SM_ShieldF_Enter;
        shieldFState  = ShieldMan.SM_ShieldF;
        shieldFExit   = ShieldMan.SM_ShieldF_Exit;
        shieldSEnter  = ShieldMan.SM_ShieldS_Enter;
        shieldSState  = ShieldMan.SM_ShieldS;
        shieldSExit   = ShieldMan.SM_ShieldS_Exit;
        shieldBEnter  = ShieldMan.SM_ShieldB_Enter;
        shieldBState  = ShieldMan.SM_ShieldB;
        shieldBExit   = ShieldMan.SM_ShieldB_Exit;
        dieEnter      = ShieldMan.SM_Die_Enter;
        dieState      = ShieldMan.SM_Die;
        dieExit       = ShieldMan.SM_Die_Exit;

        //转换
        roundtorest       = ShieldMan.SM_Round_Rest;
        resttoround       = ShieldMan.SM_Rest_Round;
        roundtovigilance  = ShieldMan.SM_Rest_Vigilance;
        vigilancetoround  = ShieldMan.SM_Vigilance_Round;
        resttovigilance   = ShieldMan.SM_Rest_Vigilance;
        vigilancetosearch = ShieldMan.SM_Vigilance_Search;
        searchtoround     = ShieldMan.SM_Search_Round;
        chasetoshieldF    = ShieldMan.SM_Chase_ShieldF;
        shieldFtochase    = ShieldMan.SM_ShieldF_Chase;
        anytohook         = ShieldMan.SM_Any_Hook;
        anytocharge       = ShieldMan.SM_Any_Charge;
        chargetoshieldF   = ShieldMan.SM_Charge_ShieldF;
        hooktoshieldF     = ShieldMan.SM_Hook_ShieldF;
        shieldStoattack   = ShieldMan.SM_ShieldS_Attack;
        attacktoshieldS   = ShieldMan.SM_Attack_ShieldS;
        shieldFtoshieldS  = ShieldMan.SM_ShieldF_ShieldS;
        shieldStoshieldF  = ShieldMan.SM_ShieldS_ShieldF;
        shieldBtowalkaway = ShieldMan.SM_ShieldB_Walkaway;
        walkawaytoshieldB = ShieldMan.SM_Walkaway_ShieldB;
        walkawaytorunaway = ShieldMan.SM_Walkaway_Runaway;
        runawaytowalkaway = ShieldMan.SM_Runaway_Walkaway;

        // 决策反馈函数
        near       = ShieldMan.SM_Near;
        far        = ShieldMan.SM_Far;
        staLose    = ShieldMan.SM_StaLose;
        staRecover = ShieldMan.SM_StaRecover;
        hurtup     = ShieldMan.SM_HurtUp;

        // 情感
        despair = ShieldMan.SM_Despair_Emotion;
        normal  = ShieldMan.SM_Normal_Emotion;
        angry   = ShieldMan.SM_Angry_Emotion;
        excited = ShieldMan.SM_Excited_Emotion;

        // 生成指定个数单位
        for (int i = 0; i < count; i++)
        {
            AIEntity mAIEntity   = new AIEntity();
            UEntity  mPlayer     = new UEntity();
            UEntity  mPlayerLast = new UEntity();

            ECSWorld.MainWorld.registerEntityAfterInit(mAIEntity);

            ECSWorld.MainWorld.registerEntityAfterInit(mPlayer);

            mAIEntity.mAI          = shieldAI;
            mAIEntity.mPlayer      = player;
            mAIEntity.PlayerEntity = mPlayer;

            mAIEntity.AIPos = new Vector3(
                gameObject.transform.position.x + Random.Range(-randomRange, randomRange), 0,
                gameObject.transform.position.z + Random.Range(-randomRange, randomRange));

            mAIEntity.Init();

            mAIEntity.AddComponent <shieldAI> (new shieldAI());
            mAIEntity.AddComponent <staComponent> (new staComponent());
            mAIEntity.AddComponent <SSHComponent> (new SSHComponent());
            mAIEntity.AddComponent <showAll> (new showAll());
            mAIEntity.AddComponent <getPlayer> (new getPlayer());
            mAIEntity.AddComponent <GYTHPComponent> (new GYTHPComponent());

            mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.SetActive(true);

            mAIEntity.GetComponent <GYTHPComponent> ().HP    = mAIEntity.GetComponent <SSHComponent> ().HP;
            mAIEntity.GetComponent <GYTHPComponent> ().HPNow = mAIEntity.GetComponent <SSHComponent> ().HP;

            animator = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.GetComponent <Animator> ();
            mAIEntity.GetComponent <AIAnimation> ().mAnimator = animator;

            mAIEntity.GetComponent <AIAnimation> ().Add("Idle", idleAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Walk", walkAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Run", runAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("ShieldWalk", shieldWalkAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("ShieldWalkBack", shieldWalkBAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("ShieldStop", shieldStopAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Die", dieAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Hook", hookAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Charge", chargeAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Attack", attackAnim);
            mAIEntity.GetComponent <AIAnimation> ().mtempAnim = "Idle";

            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Despair");
            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Normal");
            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Angry");
            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Excited");

            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Despair", despair);
            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Normal", normal);
            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Angry", angry);
            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Excited", excited);


            // 巡逻决策
            AIState state_idle = new AIState();
            state_idle.Init();
            state_idle.mName          = "SMidle";
            state_idle.mStateRecorder = mRecorder;
            state_idle.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int idle_round     = state_idle.AddExecuter(roundState, roundExit, roundEnter);
            int idle_rest      = state_idle.AddExecuter(restState, restExit, restEnter);
            int idle_vigilance = state_idle.AddExecuter(vigilanceState, vigilanceExit, vigilanceEnter);
            int idle_search    = state_idle.AddExecuter(searchState, searchExit, searchEnter);

            state_idle.AddStateName(idle_round, "Round");
            state_idle.AddStateName(idle_rest, "Rest");
            state_idle.AddStateName(idle_vigilance, "Vigilance");
            state_idle.AddStateName(idle_search, "Search");


            state_idle.AddDoubleEdge(roundtorest, resttoround, EmptyFeedbacker.Run,
                                     EmptyFeedbacker.Run, idle_round, idle_rest);
            state_idle.AddDoubleEdge(roundtovigilance, vigilancetoround, EmptyFeedbacker.Run,
                                     EmptyFeedbacker.Run, idle_round, idle_vigilance);
            state_idle.AddEdge(resttovigilance, EmptyFeedbacker.Run, idle_rest, idle_vigilance);
            // 一个反馈,距离接近
            state_idle.AddEdge(vigilancetosearch, near, idle_vigilance, idle_search);
            state_idle.AddEdge(searchtoround, EmptyFeedbacker.Run, idle_search, idle_round);

            state_idle.AddAnimation(roundState, "Walk");
            state_idle.AddAnimation(restState, "Idle");
            state_idle.AddAnimation(vigilanceState, "Idle");
            state_idle.AddAnimation(searchState, "Walk");

            state_idle.tempID = idle_round;

            int id1 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(IdleActioner, IdleEnter, IdleExit, IdleFeedbacker, state_idle);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id1, "Idle");


            // 接近决策
            AIState state_approach = new AIState();
            state_approach.Init();
            state_approach.mName          = "SMapproach";
            state_approach.mStateRecorder = mRecorder;
            state_approach.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int approach_hook    = state_approach.AddExecuter(hookState, hookExit, hookEnter);
            int approach_charge  = state_approach.AddExecuter(chargeState, chargeExit, chargeEnter);
            int approach_chase   = state_approach.AddExecuter(chaseState, chaseExit, chaseEnter);
            int approach_shieldF = state_approach.AddExecuter(shieldFState, shieldFExit, shieldFEnter);

            state_approach.AddStateName(approach_hook, "Hook");
            state_approach.AddStateName(approach_charge, "Charge");
            state_approach.AddStateName(approach_chase, "Chase");
            state_approach.AddStateName(approach_shieldF, "ShieldF");

            // 首先考虑到出钩和冲撞是个开关节点,执行完动作后就会退出,不需要反馈
            state_approach.AddAnywayTranfer(anytohook, EmptyFeedbacker.Run, approach_hook);
            state_approach.AddAnywayTranfer(anytocharge, EmptyFeedbacker.Run, approach_charge);

            state_approach.AddEdge(hooktoshieldF, EmptyFeedbacker.Run, approach_hook, approach_shieldF);
            state_approach.AddEdge(chargetoshieldF, EmptyFeedbacker.Run, approach_charge, approach_shieldF);

            state_approach.AddDoubleEdge(chasetoshieldF, shieldFtochase, staRecover, near, approach_chase, approach_shieldF);

            state_approach.AddAnimation(hookState, "Hook");             // 注意,绑定的是放慢版的出拳
            state_approach.AddAnimation(chargeState, "Charge");
            state_approach.AddAnimation(chaseState, "Run");
            state_approach.AddAnimation(shieldFState, "ShieldWalk");

            state_approach.tempID = approach_chase;


            int id2 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(ApproachActioner, ApproachEnter, ApproachExit, ApproachFeedbacker, state_approach);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id2, "Approach");

            // 攻击决策
            AIState state_attack = new AIState();
            state_attack.Init();
            state_attack.mName          = "SMattack";
            state_attack.mStateRecorder = mRecorder;
            state_attack.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());
            // 排列顺序(word中),从左到右,从上到下
            int attack_shieldF = state_attack.AddExecuter(shieldFState, shieldFExit, shieldFEnter);
            int attack_attack  = state_attack.AddExecuter(attackState, attackExit, attackEnter);
            int attack_shieldS = state_attack.AddExecuter(shieldSState, shieldSExit, shieldSEnter);

            state_attack.AddStateName(attack_shieldF, "ShieldF");
            state_attack.AddStateName(attack_attack, "Attack");
            state_attack.AddStateName(attack_shieldS, "ShieldS");

            // 举盾接近到停止,可以理解为为了恢复体力;停止到举盾接近,可以理解为为了接近
            state_attack.AddDoubleEdge(shieldFtoshieldS, shieldStoshieldF, staRecover, near, attack_shieldF, attack_shieldS);
            // 前部略,后部则是因为攻击节点,造成伤害最吼
            state_attack.AddDoubleEdge(attacktoshieldS, shieldStoattack, staRecover, hurtup, attack_attack, attack_shieldS);
            state_attack.AddAnimation(shieldFState, "ShieldWalk");
            state_attack.AddAnimation(attackState, "Attack");
            state_attack.AddAnimation(shieldSState, "ShieldStop");

            state_attack.tempID = attack_shieldF;            // 先接近总是没毛病

            int id3 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(AttackActioner, AttackEnter, AttackExit, AttackFeedbacker, state_attack);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id3, "Attack");

            // 逃跑
            AIState state_escape = new AIState();
            state_escape.Init();
            state_escape.mName          = "SMescape";
            state_escape.mStateRecorder = mRecorder;
            state_escape.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int escape_shieldB  = state_escape.AddExecuter(shieldBState, shieldFExit, shieldFEnter);
            int escape_walkaway = state_escape.AddExecuter(walkawayState, walkawayExit, walkawayEnter);
            int escape_runaway  = state_escape.AddExecuter(runawayState, runawayExit, runawayEnter);

            state_escape.AddStateName(escape_shieldB, "ShieldB");
            state_escape.AddStateName(escape_walkaway, "Walkaway");
            state_escape.AddStateName(escape_runaway, "Runaway");

            state_escape.AddDoubleEdge(shieldBtowalkaway, walkawaytoshieldB, far, far, escape_shieldB, escape_walkaway);
            state_escape.AddDoubleEdge(walkawaytorunaway, runawaytowalkaway, far, staRecover, escape_walkaway, escape_runaway);

            state_escape.AddAnimation(shieldBState, "ShieldWalkBack");
            state_escape.AddAnimation(walkawayState, "Walk");
            state_escape.AddAnimation(runawayState, "Run");

            state_escape.tempID = escape_shieldB;

            int id4 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(EscapeActioner, EscapeEnter, EscapeExit, EscapeFeedbacker, state_escape);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id4, "Escape");
//			AIState state_block = new AIState ();
//			// 中间先空着,不好说。现在的问题是,群体性行为考虑写在一个函数中,目前只有一个行为...
//
//			int id5 = mAIEntity.GetComponent<AIStrategy> ().AddStrategy (BlockActioner, BlockEnter, BlockExit, BlockFeedbacker, state_block);


            // 死亡决策
            AIState state_death = new AIState();
            state_death.Init();
            state_death.mName          = "SMdeath";
            state_death.mStateRecorder = mRecorder;
            state_death.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int death_die = state_death.AddExecuter(dieState, dieExit, dieEnter);

            state_death.AddStateName(death_die, "Die");

            state_death.AddAnimation(dieState, "Die");

            state_death.tempID = death_die;

            int id6 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(DeathActioner, DeathEnter, DeathExit, DeathFeedbacker, state_death);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id6, "Death");

            mAIEntity.GetComponent <AIStrategy> ().SetEntry(id1);

            mAIEntity.GetComponent <shieldAI> ().mRoundCenter = gameObject.transform.position +
                                                                new Vector3(Random.Range(-roundRange, roundRange), 0,
                                                                            Random.Range(-roundRange, roundRange));

            // 组件的赋值
            GameObject rt = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT;

            foreach (Transform t in rt.GetComponentsInChildren <Transform>())
            {
                if (t.name == "vs")
                {
                    mAIEntity.GetComponent <getPlayer> ().vs = t.gameObject;
                }
                else if (t.gameObject.name == "ShieldFront")
                {
                    mAIEntity.GetComponent <SSHComponent> ().shieldFObj = t.gameObject;
                }
                else if (t.gameObject.name == "ShieldBack")
                {
                    mAIEntity.GetComponent <SSHComponent> ().shieldBObj = t.gameObject;
                }
                else if (t.gameObject.name == "SwordFront")
                {
                    mAIEntity.GetComponent <SSHComponent> ().swordFObj = t.gameObject;
                }
                else if (t.gameObject.name == "SwordBack")
                {
                    mAIEntity.GetComponent <SSHComponent> ().swordBObj = t.gameObject;
                }
                else if (t.gameObject.name == "HookFront")
                {
                    mAIEntity.GetComponent <SSHComponent> ().hookFObj = t.gameObject;
                }
                else if (t.gameObject.name == "HookBack")
                {
                    mAIEntity.GetComponent <SSHComponent> ().hookBObj = t.gameObject;
                }
                else if (t.gameObject.name == "HeadC")
                {
                    mAIEntity.GetComponent <SSHComponent> ().headC = t.gameObject;
                }
            }
            mAIEntity.GetComponent <SSHComponent> ().hookThrowObj = hookThrow;

            // 为武器伤害赋值
            mAIEntity.GetComponent <SSHComponent> ().swordFObj.GetComponent <WeaponDamage> ().damage =
                mAIEntity.GetComponent <SSHComponent> ().swordDamage;
            mAIEntity.GetComponent <SSHComponent> ().hookFObj.GetComponent <WeaponDamage> ().damage =
                mAIEntity.GetComponent <SSHComponent> ().hookDamage;
            // 偶数冲锋,奇数钩子
            if (i % 2 == 0)
            {
                mAIEntity.GetComponent <SSHComponent> ().hasHook   = false;
                mAIEntity.GetComponent <SSHComponent> ().hasCharge = true;
            }
            else
            {
                mAIEntity.GetComponent <SSHComponent> ().hasHook   = true;
                mAIEntity.GetComponent <SSHComponent> ().hasCharge = false;
            }
            // 关于组行为的新加代码,在几个盾兵中,生成一个发起者
            mAIEntity.tag = "ShieldMan";
            if (i % 6 == 0)
            {
                mAIEntity.AddComponent <Group4StandardAI> (new Group4StandardAI());
                GroupManager.getInstance().AddSponsor(mAIEntity);
            }
            else
            {
                GroupManager.getInstance().AddResponse(mAIEntity);
            }

            mAIEntity.GetComponent <showAll> ().mCanvas = mCanvas;
            if (count == 1)
            {
                mAIEntity.GetComponent <showAll> ().singleTest = true;
            }
            foreach (Transform t in mCanvas.GetComponentsInChildren <Transform>())
            {
                if (t.name == "Action")
                {
                    mAIEntity.GetComponent <showAll> ().mAction = t.gameObject;
                }
                else if (t.name == "Node")
                {
                    mAIEntity.GetComponent <showAll> ().mNode = t.gameObject;
                }
                else if (t.name == "Emotion")
                {
                    mAIEntity.GetComponent <showAll> ().mEmotion = t.gameObject;
                }
                else if (t.name == "Animation")
                {
                    mAIEntity.GetComponent <showAll> ().mAnimation = t.gameObject;
                }
            }
        }
    }
コード例 #2
0
ファイル: TrapManDemo.cs プロジェクト: TianYiJT/FreedomAI
    // Use this for initialization
    void Start()
    {
        // 决策机
        IdleEnter      = TrapMan.IdleEnter;
        IdleExit       = TrapMan.IdleExit;
        IdleFeedbacker = TrapMan.IdleFeedbacker;
        IdleActioner   = TrapMan.IdleAction;

        AttackEnter      = TrapMan.AttackEnter;
        AttackExit       = TrapMan.AttackExit;
        AttackFeedbacker = TrapMan.AttackFeedbacker;
        AttackActioner   = TrapMan.AttackAction;

        EscapeEnter      = TrapMan.EscapeEnter;
        EscapeExit       = TrapMan.EscapeExit;
        EscapeFeedbacker = TrapMan.EscapeFeedbacker;
        EscapeActioner   = TrapMan.EscapeAction;

        BlockEnter      = TrapMan.BlockEnter;
        BlockExit       = TrapMan.BlockExit;
        BlockFeedbacker = TrapMan.BlockFeedbacker;
        BlockActioner   = TrapMan.BlockAction;

        DeathEnter      = TrapMan.DeathEnter;
        DeathExit       = TrapMan.DeathExit;
        DeathFeedbacker = TrapMan.DeathFeedbacker;
        DeathActioner   = TrapMan.DeathAction;

        idleAnim  = TrapMan.TM_idle_Anim;
        walkAnim  = TrapMan.TM_Walk_Anim;
        sneakAnim = TrapMan.TM_Sneak_Anim;
        runAnim   = TrapMan.TM_Run_Anim;
        waryAnim  = TrapMan.TM_Wary_Anim;
        aimAnim   = TrapMan.TM_Aim_Anim;
        fireAnim  = TrapMan.TM_Fire_Anim;
        dieAnim   = TrapMan.TM_Die_Anim;

        mRecorder = TrapMan.TM_Recorder;

        // 节点
        roundEnter     = TrapMan.TM_Round_Enter;
        roundState     = TrapMan.TM_Round;
        roundExit      = TrapMan.TM_Round_Exit;
        restEnter      = TrapMan.TM_Rest_Enter;
        restState      = TrapMan.TM_Rest;
        restExit       = TrapMan.TM_Rest_Exit;
        vigilanceEnter = TrapMan.TM_Vigilance_Enter;
        vigilanceState = TrapMan.TM_Vigilance;
        vigilanceExit  = TrapMan.TM_Vigilance_Exit;
        searchEnter    = TrapMan.TM_Search_Enter;
        searchState    = TrapMan.TM_Search;
        searchExit     = TrapMan.TM_Search_Exit;

        waryEnter      = TrapMan.TM_Wary_Enter;
        waryState      = TrapMan.TM_Wary;
        waryExit       = TrapMan.TM_Wary_Exit;
        findcoverEnter = TrapMan.TM_Findcover_Enter;
        findcoverState = TrapMan.TM_Findcover;
        findcoverExit  = TrapMan.TM_Findcover_Exit;
        aimEnter       = TrapMan.TM_Aim_Enter;
        aimState       = TrapMan.TM_Aim;
        aimExit        = TrapMan.TM_Aim_Exit;
        fireEnter      = TrapMan.TM_Fire_Enter;
        fireState      = TrapMan.TM_Fire;
        fireExit       = TrapMan.TM_Fire_Exit;
        trapEnter      = TrapMan.TM_Trap_Enter;
        trapState      = TrapMan.TM_Trap;
        trapExit       = TrapMan.TM_Trap_Exit;
        barrierEnter   = TrapMan.TM_Barrier_Enter;
        barrierState   = TrapMan.TM_Barrier;
        barrierExit    = TrapMan.TM_Barrier_Exit;
        dieEnter       = TrapMan.TM_Die_Enter;
        dieState       = TrapMan.TM_Die;
        dieExit        = TrapMan.TM_Die_Exit;

        // 转换
        roundtorest       = TrapMan.TM_Round_Rest;
        resttoround       = TrapMan.TM_Rest_Round;
        roundtovigilance  = TrapMan.TM_Rest_Vigilance;
        vigilancetoround  = TrapMan.TM_Vigilance_Round;
        resttovigilance   = TrapMan.TM_Rest_Vigilance;
        vigilancetosearch = TrapMan.TM_Vigilance_Search;
        searchtoround     = TrapMan.TM_Search_Round;


        warytofindcover    = TrapMan.TM_Wary_Findcover;
        findcovertowary    = TrapMan.TM_Findcover_Wary;
        barriertofindcover = TrapMan.TM_Barrier_Findcover;
        findcovertoaim     = TrapMan.TM_Findcover_Aim;
        aimtofire          = TrapMan.TM_Aim_Fire;
        firetofindcover    = TrapMan.TM_Fire_Findcover;
        findcovertotrap    = TrapMan.TM_Findcover_Trap;
        traptofindcover    = TrapMan.TM_Trap_Findcover;

        // 决策反馈函数
        near   = TrapMan.TM_Near;
        far    = TrapMan.TM_Far;
        hurtup = TrapMan.TM_HurtUp;

        despair = TrapMan.TM_Despair_Emotion;
        normal  = TrapMan.TM_Normal_Emotion;
        angry   = TrapMan.TM_Angry_Emotion;

        for (int i = 0; i < count; i++)
        {
            AIEntity mAIEntity   = new AIEntity();
            UEntity  mPlayer     = new UEntity();
            UEntity  mPlayerLast = new UEntity();

            ECSWorld.MainWorld.registerEntityAfterInit(mAIEntity);

            ECSWorld.MainWorld.registerEntityAfterInit(mPlayer);

            mAIEntity.mAI          = trapAI;
            mAIEntity.mPlayer      = player;
            mAIEntity.PlayerEntity = mPlayer;
            mAIEntity.AIPos        = new Vector3(gameObject.transform.position.x + Random.Range(-randomRange, randomRange), 0,
                                                 gameObject.transform.position.z + Random.Range(-randomRange, randomRange));

            mAIEntity.Init();

            mAIEntity.AddComponent <trapAI> (new trapAI());
            mAIEntity.GetComponent <trapAI> ().mAStarComputerformula = new AStarComputerformula();
            mAIEntity.GetComponent <trapAI> ().mAStarComputerformula.Add(DefaultFunc.AStarByEulerDistance, 1.0f);
            mAIEntity.AddComponent <trapComponent> (new trapComponent());
            mAIEntity.AddComponent <getPlayer> (new getPlayer());
            mAIEntity.AddComponent <GYTHPComponent> (new GYTHPComponent());
            mAIEntity.AddComponent <showAll> (new showAll());

            mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.SetActive(true);

            mAIEntity.GetComponent <GYTHPComponent> ().HP    = mAIEntity.GetComponent <trapAI> ().HP;
            mAIEntity.GetComponent <GYTHPComponent> ().HPNow = mAIEntity.GetComponent <trapAI> ().HP;

            animator = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.GetComponent <Animator> ();
            mAIEntity.GetComponent <AIAnimation> ().mAnimator = animator;

            mAIEntity.GetComponent <AIAnimation> ().Add("Idle", idleAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Walk", walkAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Sneak", sneakAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Run", runAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Wary", waryAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Aim", aimAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Fire", fireAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Die", dieAnim);
            mAIEntity.GetComponent <AIAnimation> ().mtempAnim = "Idle";

            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Despair");
            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Normal");
            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Angry");

            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Despair", despair);
            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Normal", normal);
            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Angry", angry);


            // 巡逻决策
            AIState state_idle = new AIState();
            state_idle.Init();
            state_idle.mName          = "TMidle";
            state_idle.mStateRecorder = mRecorder;
            state_idle.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int idle_round     = state_idle.AddExecuter(roundState, roundExit, roundEnter);
            int idle_rest      = state_idle.AddExecuter(restState, restExit, restEnter);
            int idle_vigilance = state_idle.AddExecuter(vigilanceState, vigilanceExit, vigilanceEnter);
            int idle_search    = state_idle.AddExecuter(searchState, searchExit, searchEnter);

            state_idle.AddStateName(idle_round, "Round");
            state_idle.AddStateName(idle_rest, "Rest");
            state_idle.AddStateName(idle_vigilance, "Vigilance");
            state_idle.AddStateName(idle_search, "Search");

            state_idle.AddDoubleEdge(roundtorest, resttoround, EmptyFeedbacker.Run,
                                     EmptyFeedbacker.Run, idle_round, idle_rest);
            state_idle.AddDoubleEdge(roundtovigilance, vigilancetoround, EmptyFeedbacker.Run,
                                     EmptyFeedbacker.Run, idle_round, idle_vigilance);
            state_idle.AddEdge(resttovigilance, EmptyFeedbacker.Run, idle_rest, idle_vigilance);
            state_idle.AddEdge(vigilancetosearch, near, idle_vigilance, idle_search);
            state_idle.AddEdge(searchtoround, EmptyFeedbacker.Run, idle_search, idle_round);

            state_idle.AddAnimation(roundState, "Walk");
            state_idle.AddAnimation(restState, "Wary");
            state_idle.AddAnimation(vigilanceState, "Idle");
            state_idle.AddAnimation(searchState, "Walk");

            state_idle.tempID = idle_round;

            int id1 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(IdleActioner, IdleEnter, IdleExit, IdleFeedbacker, state_idle);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id1, "Idle");

            // 射击,陷阱
            AIState state_attack = new AIState();
            state_attack.Init();
            state_attack.mName          = "TMattack";
            state_attack.mStateRecorder = mRecorder;
            state_attack.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int attack_wary      = state_attack.AddExecuter(waryState, waryExit, waryEnter);
            int attack_barrier   = state_attack.AddExecuter(barrierState, barrierExit, barrierEnter);
            int attack_findcover = state_attack.AddExecuter(findcoverState, findcoverExit, findcoverEnter);
            int attack_trap      = state_attack.AddExecuter(trapState, trapExit, trapEnter);
            int attack_aim       = state_attack.AddExecuter(aimState, aimExit, aimEnter);
            int attack_fire      = state_attack.AddExecuter(fireState, fireExit, fireEnter);

            state_attack.AddStateName(attack_wary, "Wary");
            state_attack.AddStateName(attack_barrier, "Barrier");
            state_attack.AddStateName(attack_findcover, "Findcover");
            state_attack.AddStateName(attack_trap, "Trap");
            state_attack.AddStateName(attack_aim, "Aim");
            state_attack.AddStateName(attack_fire, "Fire");

            state_attack.AddEdge(barriertofindcover, near, attack_barrier, attack_findcover);
            // 玩家接近的时候,寻找掩体价值更高;玩家远离时,可以休息一下
            state_attack.AddDoubleEdge(warytofindcover, findcovertowary, near, far, attack_wary, attack_findcover);
            state_attack.AddEdge(findcovertoaim, far, attack_findcover, attack_aim);
            state_attack.AddEdge(aimtofire, hurtup, attack_aim, attack_fire);
            state_attack.AddEdge(firetofindcover, near, attack_fire, attack_findcover);
            state_attack.AddDoubleEdge(findcovertotrap, traptofindcover, EmptyFeedbacker.Run, near, attack_findcover, attack_trap);

            state_attack.AddAnimation(waryState, "Wary");
            state_attack.AddAnimation(barrierState, "Idle");
            state_attack.AddAnimation(findcoverState, "Run");
            state_attack.AddAnimation(trapState, "Wary");
            state_attack.AddAnimation(aimState, "Aim");
            state_attack.AddAnimation(fireState, "Fire");

            state_attack.tempID = attack_barrier;            // 造掩体真他么开心啊

            int id2 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(AttackActioner, AttackEnter, AttackExit, AttackFeedbacker, state_attack);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id2, "Attack");


            // 逃跑决策
            AIState state_escape = new AIState();
            state_escape.Init();
            state_escape.mName          = "TMescape";
            state_escape.mStateRecorder = mRecorder;
            state_escape.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int escape_findcover = state_escape.AddExecuter(findcoverState, findcoverExit, findcoverEnter);
            int escape_trap      = state_escape.AddExecuter(trapState, trapExit, trapEnter);
            int escape_wary      = state_escape.AddExecuter(waryState, waryExit, waryEnter);

            state_escape.AddStateName(escape_findcover, "Findcover");
            state_escape.AddStateName(escape_trap, "Trap");
            state_escape.AddStateName(escape_wary, "Wary");

            state_escape.AddDoubleEdge(warytofindcover, findcovertowary, near, far, attack_wary, attack_findcover);
            state_escape.AddDoubleEdge(findcovertotrap, traptofindcover, EmptyFeedbacker.Run, EmptyFeedbacker.Run, attack_findcover, attack_trap);

            state_escape.AddAnimation(waryState, "Wary");
            state_escape.AddAnimation(trapState, "Idle");
            state_escape.AddAnimation(findcoverState, "Run");

            state_escape.tempID = escape_findcover;


            int id3 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(EscapeActioner, EscapeEnter, EscapeExit, EscapeFeedbacker, state_escape);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id3, "Escape");
            // 死亡决策
            AIState state_death = new AIState();
            state_death.Init();
            state_death.mName          = "TMdeath";
            state_death.mStateRecorder = mRecorder;
            state_death.LastEntityData.AddComponent <SMREComponent> (new SMREComponent());

            int death_die = state_death.AddExecuter(dieState, dieExit, dieEnter);
            state_death.AddStateName(death_die, "Die");

            state_death.AddAnimation(dieState, "Die");

            state_death.tempID = death_die;

            int id6 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(DeathActioner, DeathEnter, DeathExit, DeathFeedbacker, state_death);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id6, "Death");


            mAIEntity.GetComponent <AIStrategy> ().SetEntry(id1);

            mAIEntity.GetComponent <trapAI> ().mRoundCenter = player.transform.position +
                                                              new Vector3(Random.Range(-roundRange, roundRange), 0, Random.Range(-roundRange, roundRange));


            mAIEntity.GetComponent <trapAI> ().trapBallObj = trapBallObj;
            mAIEntity.GetComponent <trapAI> ().bulletObj   = bulletObj;
            mAIEntity.GetComponent <trapAI> ().barrierObj  = barrierObj;

            GameObject rt = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT;
            // 寻找,并赋值警戒圆盘和射击位置
            foreach (Transform t in rt.GetComponentsInChildren <Transform>())
            {
                if (t.name == "vs")
                {
                    mAIEntity.GetComponent <getPlayer> ().vs = t.gameObject;
                }
                else if (t.name == "FirePos")
                {
                    mAIEntity.GetComponent <trapAI> ().shootPoint = t.gameObject;
                }
                else if (t.name == "RigHead")
                {
                    mAIEntity.GetComponent <trapAI> ().RigHead = t.gameObject;
                }
            }
            // 组行为,一般都是发起者
            mAIEntity.tag = "TrapMan";
            if (i % 2 == 0)
            {
                mAIEntity.AddComponent <Group4StandardAI> (new Group4StandardAI());
                GroupManager.getInstance().AddSponsor(mAIEntity);
            }
            else
            {
                GroupManager.getInstance().AddResponse(mAIEntity);
            }

            mAIEntity.GetComponent <showAll> ().mCanvas = mCanvas;
            if (count == 1)
            {
                mAIEntity.GetComponent <showAll> ().singleTest = true;
            }
            foreach (Transform t in mCanvas.GetComponentsInChildren <Transform>())
            {
                if (t.name == "Action")
                {
                    mAIEntity.GetComponent <showAll> ().mAction = t.gameObject;
                }
                else if (t.name == "Node")
                {
                    mAIEntity.GetComponent <showAll> ().mNode = t.gameObject;
                }
                else if (t.name == "Emotion")
                {
                    mAIEntity.GetComponent <showAll> ().mEmotion = t.gameObject;
                }
                else if (t.name == "Animation")
                {
                    mAIEntity.GetComponent <showAll> ().mAnimation = t.gameObject;
                }
            }
        }
    }
コード例 #3
0
ファイル: FuSMDemo.cs プロジェクト: TianYiJT/FreedomAI
    void Start()
    {
        ECSWorld.MainWorld.registerEntityAfterInit(mAIEntity);
        ECSWorld.MainWorld.registerEntityAfterInit(mPlayer);
        IdleActioner    = FuSMTest.IdleAction;
        RunAwayActioner = FuSMTest.RunAwayAction;
        BattleState     = FuSMTest.Battle;
        Gre2Run         = FuSMTest.Gre2Runaway;
        runAnim         = TestFSM.FSM_Run_Anim;
        walkAnim        = TestFSM.FSM_Walk_Anim;
        idleAnim        = TestFSM.FSM_Idle_Anim;
        shootAnim       = TestFSM.FSM_Shoot_Anim;
        mRecorder       = TestFSM.FSM_Test_Recorder;
        runstate        = TestFSM.FSM_Run;
        roundstate      = TestFSM.FSM_Round;
        runExit         = TestFSM.FSM_Run_Exit;
        firestate       = TestFSM.FSM_Fire;
        fireExit        = TestFSM.FSM_Fire_Exit;
        Grenatestate    = TestFSM.FSM_Grenate;
        GreExit         = TestFSM.FSM_Gre_Exit;
        runawaystate    = TestFSM.FSM_Runaway;
        anytorunaway    = TestFSM.FSM_Any_TransferRunAway;
        firetoGre       = TestFSM.FSM_Fire_Gre;
        Gretofire       = TestFSM.FSM_Gre_Fire;
        firetorun       = TestFSM.FSM_Fire_Run;
        runtofire       = TestFSM.FSM_Run_Fire;
        runtoround      = TestFSM.FSM_Run_Round;
        roundtorun      = TestFSM.FSM_Round_Run;
        runtogre        = TestFSM.FSM_Run_Gre;
        gretorun        = TestFSM.FSM_Gre_Run;
        runIN           = TestFSM.FSM_RunIN;
        runOUT          = TestFSM.FSM_RunOUT;
        hurtup          = TestFSM.FSM_HurtUp;
        fear            = TestFSM.FSM_Fear;
        happy           = TestFSM.FSM_Happy;
        tired           = TestFSM.FSM_Tired;
        //	mAIEntity.forward_Object = forward_Object;
        mAIEntity.mAI          = AI;
        mAIEntity.mPlayer      = player;
        mAIEntity.PlayerEntity = mPlayer;
        mAIEntity.AIPos        = player.transform.position + new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
        mAIEntity.Init();
        mAIEntity.AddComponent <myAI> (new myAI());
        mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.SetActive(true);
        mAIEntity.PlayerEntity = mPlayer;
        mAIEntity.GetComponent <HPComponent> ().allHP  = 500;
        mAIEntity.GetComponent <HPComponent> ().tempHP = 500;
        animator = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.GetComponent <Animator> ();
        mAIEntity.GetComponent <AIAnimation> ().mAnimator = animator;
        mAIEntity.GetComponent <AIAnimation> ().Add("Run", runAnim);
        mAIEntity.GetComponent <AIAnimation> ().Add("Walk", walkAnim);
        mAIEntity.GetComponent <AIAnimation> ().Add("Idle", idleAnim);
        mAIEntity.GetComponent <AIAnimation> ().Add("Attack", shootAnim);
        mAIEntity.GetComponent <AIAnimation>().mtempAnim = "Run";
        mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Happy");
        mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Fear");
        mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Tired");
        mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Happy", happy);
        mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Fear", fear);
        mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Tired", tired);



        AIState state_idle = new AIState();

        state_idle.Init();
        int idle_round = state_idle.AddExecuter(roundstate, EmptyExitAndEnter.EmptyExit, EmptyExitAndEnter.EmptyEnter);
        int idle_run   = state_idle.AddExecuter(runstate, runExit, EmptyExitAndEnter.EmptyEnter);
        int idle_fire  = state_idle.AddExecuter(firestate, fireExit, EmptyExitAndEnter.EmptyEnter);

        state_idle.AddDoubleEdge(roundtorun, runtoround, runIN, EmptyFeedbacker.Run, idle_round, idle_run);
        state_idle.AddDoubleEdge(runtofire, firetorun, hurtup, runIN, idle_run, idle_fire);
        state_idle.AddAnimation(roundstate, "Walk");
        state_idle.AddAnimation(runstate, "Run");
        state_idle.AddAnimation(firestate, "Attack");
        state_idle.tempID = idle_round;
        //state_idle.mName = "Idle";
        state_idle.mStateRecorder = mRecorder;
        state_idle.LastEntityData.AddComponent <HPComponent> (new HPComponent());
        state_idle.LastEntityData.PlayerEntity = mPlayerLast;
        int id2 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(IdleActioner, EmptyStrategyEnter.Run, EmptyStrategyExit.Run, EmptyStrategyFeedbacker.Run, state_idle);

        AIState state_runaway = new AIState();

        state_runaway.Init();
        int idle_runaway = state_runaway.AddExecuter(runawaystate, EmptyExitAndEnter.EmptyExit, EmptyExitAndEnter.EmptyEnter);
        int idle_gre     = state_runaway.AddExecuter(Grenatestate, GreExit, EmptyExitAndEnter.EmptyEnter);

        state_runaway.AddDoubleEdge(anytorunaway, Gre2Run, runOUT, runOUT, idle_gre, idle_runaway);
        state_runaway.AddAnimation(runawaystate, "Run");
        state_runaway.AddAnimation(Grenatestate, "Idle");
        state_runaway.tempID         = idle_runaway;
        state_runaway.mStateRecorder = mRecorder;
        state_runaway.LastEntityData.AddComponent <HPComponent> (new HPComponent());
        state_runaway.LastEntityData.PlayerEntity = mPlayerLast;
        int id1 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(RunAwayActioner, EmptyStrategyEnter.Run, EmptyStrategyExit.Run, EmptyStrategyFeedbacker.Run, state_runaway);

        //	mAIEntity.GetComponent<AIStrategy> ().InitAvoid (BattleState,EmptyExitAndEnter.EmptyEnter,EmptyExitAndEnter.EmptyExit,mRecorder,state_runaway.LastEntityData);
        mAIEntity.GetComponent <AIStrategy> ().SetEntry(id2);


        mPlayerLast.AddComponent <HPComponent> (playerLast_hp);
        mAIEntity.GetComponent <myAI> ().fireObject    = shootObject;
        mAIEntity.GetComponent <myAI> ().GrenateObject = GrenateObject;
        mAIEntity.GetComponent <myAI>().mRoundCenter   = player.transform.position + new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
        player_hp.allHP  = 700;
        player_hp.tempHP = 700;
        mPlayer.AddComponent <HPComponent> (player_hp);
    }
コード例 #4
0
ファイル: BombManDemo.cs プロジェクト: TianYiJT/FreedomAI
    // Use this for initialization
    void Start()
    {
        // 决策机
        IdleEnter      = BombMan.IdleEnter;
        IdleExit       = BombMan.IdleExit;
        IdleFeedbacker = BombMan.IdleFeedbacker;
        IdleActioner   = BombMan.IdleAction;

        DoomEnter      = BombMan.DoomEnter;
        DoomExit       = BombMan.DoomExit;
        DoomFeedbacker = BombMan.DoomFeedbacker;
        DoomActioner   = BombMan.DoomAction;

        DeathEnter      = BombMan.DeathEnter;
        DeathExit       = BombMan.DeathExit;
        DeathFeedbacker = BombMan.DeathFeedbacker;
        DeathActioner   = BombMan.DeathAction;

        // 动画
        idleAnim      = BombMan.BM_idle_Anim;
        restAnim      = BombMan.BM_rest_Anim;
        walkAnim      = BombMan.BM_walk_Anim;
        vigilanceAnim = BombMan.BM_vigilance_Anim;
        crazyrunAnim  = BombMan.BM_crazyrun_Anim;
        readyblowAnim = BombMan.BM_readyblow_Anim;
        dieAnim       = BombMan.BM_die_Anim;

        mRecorder = BombMan.BM_Recorder;

        roundEnter     = BombMan.BM_Round_Enter;
        roundState     = BombMan.BM_Round;
        roundExit      = BombMan.BM_Round_Exit;
        restEnter      = BombMan.BM_Rest_Enter;
        restState      = BombMan.BM_Rest;
        restExit       = BombMan.BM_Rest_Exit;
        vigilanceEnter = BombMan.BM_Vigilance_Enter;
        vigilanceState = BombMan.BM_Vigilance;
        vigilanceExit  = BombMan.BM_Vigilance_Exit;
        searchEnter    = BombMan.BM_Search_Enter;
        searchState    = BombMan.BM_Search;
        searchExit     = BombMan.BM_Search_Exit;
        crazyrunEnter  = BombMan.BM_Crazyrun_Enter;
        crazyrunState  = BombMan.BM_Crazyrun;
        crazyrunExit   = BombMan.BM_Crazyrun_Exit;
        delayEnter     = BombMan.BM_Delay_Enter;
        delayState     = BombMan.BM_Delay;
        delayExit      = BombMan.BM_Delay_Exit;
        boomEnter      = BombMan.BM_Boom_Enter;
        boomState      = BombMan.BM_Boom;
        boomExit       = BombMan.BM_Boom_Exit;

        roundtorest       = BombMan.BM_Round_Rest;
        resttoround       = BombMan.BM_Rest_Round;
        roundtovigilance  = BombMan.BM_Rest_Vigilance;
        vigilancetoround  = BombMan.BM_Vigilance_Round;
        resttovigilance   = BombMan.BM_Rest_Vigilance;
        vigilancetosearch = BombMan.BM_Vigilance_Search;
        searchtoround     = BombMan.BM_Search_Round;
        crazyruntodelay   = BombMan.BM_Crazyrun_Delay;

        // 情感
        normal = BombMan.BM_Normal_Emotion;
        angry  = BombMan.BM_Angry_Emotion;

        // 生成指定个数单位
        for (int i = 0; i < count; i++)
        {
            AIEntity mAIEntity   = new AIEntity();
            UEntity  mPlayer     = new UEntity();
            UEntity  mPlayerLast = new UEntity();

            ECSWorld.MainWorld.registerEntityAfterInit(mAIEntity);

            ECSWorld.MainWorld.registerEntityAfterInit(mPlayer);

            // 在init前,完成这三个初始化
            mAIEntity.mAI          = bombAI;
            mAIEntity.mPlayer      = player;
            mAIEntity.PlayerEntity = mPlayer;

            mAIEntity.AIPos = new Vector3(
                gameObject.transform.position.x + Random.Range(-randomRange, randomRange), 0,
                gameObject.transform.position.z + Random.Range(-randomRange, randomRange));
            mAIEntity.Init();

            mAIEntity.AddComponent <bombAI> (new bombAI());
            mAIEntity.AddComponent <getPlayer> (new getPlayer());
            mAIEntity.AddComponent <showAll> (new showAll());

            mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.SetActive(true);

            animator = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT.GetComponent <Animator> ();
            mAIEntity.GetComponent <AIAnimation> ().mAnimator = animator;

            mAIEntity.GetComponent <AIAnimation> ().Add("Idle", idleAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Rest", restAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Walk", walkAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Vigilance", vigilanceAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Crazyrun", crazyrunAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Readyblow", readyblowAnim);
            mAIEntity.GetComponent <AIAnimation> ().Add("Die", dieAnim);

            mAIEntity.GetComponent <AIAnimation> ().mtempAnim = "Idle";

            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Normal");
            mAIEntity.GetComponent <AIEmotion> ().InsertEmotion("Angry");

            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Normal", normal);
            mAIEntity.GetComponent <AIEmotion> ().InsertEdge("Angry", angry);

            // 上段完

            // 巡逻决策
            AIState state_idle = new AIState();
            state_idle.Init();
            state_idle.mStateRecorder = EmptyExitAndEnter.EmptyEnter;

            int idle_round     = state_idle.AddExecuter(roundState, roundExit, roundEnter);
            int idle_rest      = state_idle.AddExecuter(restState, restExit, restEnter);
            int idle_vigilance = state_idle.AddExecuter(vigilanceState, vigilanceExit, vigilanceEnter);
            int idle_search    = state_idle.AddExecuter(searchState, searchExit, searchEnter);

            state_idle.AddStateName(idle_round, "Round");
            state_idle.AddStateName(idle_rest, "Rest");
            state_idle.AddStateName(idle_vigilance, "Vigilance");
            state_idle.AddStateName(idle_search, "Search");

            state_idle.AddDoubleEdge(roundtorest, resttoround, EmptyFeedbacker.Run,
                                     EmptyFeedbacker.Run, idle_round, idle_rest);
            state_idle.AddDoubleEdge(roundtovigilance, vigilancetoround, EmptyFeedbacker.Run,
                                     EmptyFeedbacker.Run, idle_round, idle_vigilance);
            state_idle.AddEdge(resttovigilance, EmptyFeedbacker.Run, idle_rest, idle_vigilance);
            state_idle.AddEdge(vigilancetosearch, EmptyFeedbacker.Run, idle_vigilance, idle_search);
            state_idle.AddEdge(searchtoround, EmptyFeedbacker.Run, idle_search, idle_round);

            state_idle.AddAnimation(roundState, "Walk");
            state_idle.AddAnimation(restState, "Rest");
            state_idle.AddAnimation(vigilanceState, "Vigilance");
            state_idle.AddAnimation(searchState, "Walk");

            state_idle.tempID = idle_round;

            int id1 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(IdleActioner, IdleEnter, IdleExit, IdleFeedbacker, state_idle);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id1, "Idle");


            // 自爆决策
            AIState state_doom = new AIState();
            state_doom.Init();
            state_doom.mStateRecorder = EmptyExitAndEnter.EmptyEnter;

            int doom_crazyrun = state_doom.AddExecuter(crazyrunState, crazyrunExit, crazyrunEnter);
            int doom_delay    = state_doom.AddExecuter(delayState, delayExit, delayEnter);

            state_doom.AddStateName(doom_crazyrun, "CrazyRun");
            state_doom.AddStateName(doom_delay, "Delay");

            state_doom.AddEdge(crazyruntodelay, EmptyFeedbacker.Run, doom_crazyrun, doom_delay);

            state_doom.AddAnimation(crazyrunState, "Crazyrun");
            state_doom.AddAnimation(delayState, "Readyblow");

            state_doom.tempID = doom_crazyrun;

            int id2 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(DoomActioner, DoomEnter, DoomExit, DoomFeedbacker, state_doom);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id2, "Doom");

            // 死亡决策
            AIState state_death = new AIState();
            state_death.Init();
            state_death.mStateRecorder = EmptyExitAndEnter.EmptyEnter;

            int death_boom = state_death.AddExecuter(boomState, boomExit, boomEnter);
            state_death.AddStateName(death_boom, "Boom");

            state_death.AddAnimation(boomState, "Die");

            state_death.tempID = death_boom;

            int id3 = mAIEntity.GetComponent <AIStrategy> ().AddStrategy(DeathActioner, DeathEnter, DeathExit, DeathFeedbacker, state_death);
            mAIEntity.GetComponent <AIStrategy> ().AddName(id3, "Death");

            mAIEntity.GetComponent <AIStrategy> ().SetEntry(id1);


            mAIEntity.GetComponent <bombAI> ().mRoundCenter = gameObject.transform.position +
                                                              new Vector3(Random.Range(-roundRange, roundRange), 0,
                                                                          Random.Range(-roundRange, roundRange));

            GameObject rt = mAIEntity.GetComponent <BaseAIComponent> ().mAIRT;

            foreach (Transform t in rt.GetComponentsInChildren <Transform>())
            {
                if (t.name == "vs")
                {
                    mAIEntity.GetComponent <getPlayer> ().vs = t.gameObject;
                }
                else if (t.name == "RigHead")
                {
                    mAIEntity.GetComponent <bombAI> ().RigHead = t.gameObject;
                }
            }

            mAIEntity.GetComponent <showAll> ().mCanvas = mCanvas;
            if (count == 1)
            {
                mAIEntity.GetComponent <showAll> ().singleTest = true;
            }
            foreach (Transform t in mCanvas.GetComponentsInChildren <Transform>())
            {
                if (t.name == "Action")
                {
                    mAIEntity.GetComponent <showAll> ().mAction = t.gameObject;
                }
                else if (t.name == "Node")
                {
                    mAIEntity.GetComponent <showAll> ().mNode = t.gameObject;
                }
                else if (t.name == "Emotion")
                {
                    mAIEntity.GetComponent <showAll> ().mEmotion = t.gameObject;
                }
                else if (t.name == "Animation")
                {
                    mAIEntity.GetComponent <showAll> ().mAnimation = t.gameObject;
                }
            }

            mAIEntity.tag = "BombMan";
            GroupManager.getInstance().AddResponse(mAIEntity);
        }
    }