Beispiel #1
0
    void Start()
    {
        group_return        = TestGroup.Test_Group_Return;
        group_round         = TestGroup.Test_Group_Round;
        return2round        = TestGroup.Test_Group_Return2Round;
        groupStrategy       = TestGroup.Test_Group_Strategy;
        GStrategyEnter      = TestGroup.Test_Group_Enter;
        GDissolve           = TestGroup.Test_Group_Disslove;
        GAlloc              = TestGroup.Test_Group_Alloc;
        Round               = TestGroup.Test_Round;
        RoundExit           = TestGroup.Test_Round_Exit;
        Idle                = TestGroup.Test_Idle;
        IdleExit            = TestGroup.Test_Idle_Exit;
        Idle2Round          = TestGroup.Test_Idle2Round;
        Round2Idle          = TestGroup.Test_Round2Idle;
        walkPlay            = TestFSM.FSM_Walk_Anim;
        IdlePlay            = TestFSM.FSM_Idle_Anim;
        group_cube_strategy = TestGroup.Test_Group_CubeStrategy;
        group_return_cube   = TestGroup.Test_Group_Return_Cube;


        GroupBehaviourNode gbn = new GroupBehaviourNode(); gbn.mCount = 4; gbn.mRoleName = "Test";

        List <GroupBehaviourNode> gbnList = new List <GroupBehaviourNode> (); gbnList.Add(gbn);

        GroupManager.getInstance().AddGroupList(gbnList, GDissolve, groupStrategy, GAlloc, GStrategyEnter, EmptyGroupFunc.StrategyExit);



        AIGroupState aiGroupState = new AIGroupState();

        int id_group_return = aiGroupState.AddGroupState(group_return, TestGroup.Test_Group_Return_Enter, EmptyGroupFunc.StateExit);
        int id_group_round  = aiGroupState.AddGroupState(group_round, EmptyGroupFunc.StateEnter, EmptyGroupFunc.StateExit);

        aiGroupState.AddAnim(id_group_return, TestGroup.Test_Group_Return_Anim);
        aiGroupState.AddAnim(id_group_round, TestGroup.Test_Group_Round_Anim);

        aiGroupState.AddTransfer(id_group_return, id_group_round, return2round);
        aiGroupState.tempID = id_group_return;
        GroupManager.getInstance().AddStrategy("Test", 0, aiGroupState);


        GroupBehaviourNode gbn_cube1 = new GroupBehaviourNode(); gbn_cube1.mCount = 2; gbn_cube1.mRoleName = "Test";
        GroupBehaviourNode gbn_cube2 = new GroupBehaviourNode(); gbn_cube2.mCount = 3; gbn_cube2.mRoleName = "Test1";

        List <GroupBehaviourNode> gbncubeList = new List <GroupBehaviourNode> (); gbncubeList.Add(gbn_cube1); gbncubeList.Add(gbn_cube2);

        GroupManager.getInstance().AddGroupList(gbncubeList, GDissolve, group_cube_strategy, GAlloc, GStrategyEnter, EmptyGroupFunc.StrategyExit);

        AIGroupState aiGroupState1 = new AIGroupState();
        int          id_cube_group = aiGroupState1.AddGroupState(group_return_cube, TestGroup.Test_Group_Return_Enter, EmptyGroupFunc.StateExit);

        aiGroupState1.AddAnim(id_group_return, TestGroup.Test_Group_Return_Anim);
        aiGroupState1.AddAnim(id_group_round, TestGroup.Test_Group_Round_Anim);
        aiGroupState1.tempID = id_cube_group;
        GroupManager.getInstance().AddStrategy("Test1", 1, aiGroupState1);



        List <int> key1 = new List <int>(); key1.Add(1);

        GroupManager.getInstance().AddKey("Test1", key1);

        List <int> key = new List <int>(); key.Add(0);

        GroupManager.getInstance().AddKey("Test", key);

        GroupManager.getInstance().mCheckDistance = 20.0f;


        for (int i = 0; i < count; i++)
        {
            AIEntity pEntity = new AIEntity();
            pEntity.tag = "Test";
            UEntity mPlayer     = new UEntity();
            UEntity mPlayerLast = new UEntity();
            pEntity.mAI     = groupAIDemo;
            pEntity.mPlayer = position;
            pEntity.AIPos   = position.transform.position + new Vector3(Random.Range(-20, 20), 0, Random.Range(-20, 20));
            ECSWorld.MainWorld.registerEntityAfterInit(pEntity);
            pEntity.Init();
            pEntity.AddComponent <myAI> (new myAI());
            pEntity.AddComponent <myGroupAI> (new myGroupAI());
            pEntity.GetComponent <BaseAIComponent> ().mAIRT.SetActive(true);
            pEntity.PlayerEntity = mPlayer;
            animator             = pEntity.GetComponent <BaseAIComponent> ().mAIRT.GetComponent <Animator> ();
            pEntity.GetComponent <AIAnimation> ().mAnimator = animator;
            pEntity.GetComponent <AIAnimation> ().Add("Idle", IdlePlay);
            pEntity.GetComponent <AIAnimation> ().Add("Walk", walkPlay);
            pEntity.GetComponent <AIAnimation>().mtempAnim = "Walk";
            int id_round = pEntity.GetComponent <AIState> ().AddExecuter(Round, RoundExit, EmptyExitAndEnter.EmptyEnter);
            //int id_idle = pEntity.GetComponent<AIState> ().AddExecuter (Idle,IdleExit,EmptyExitAndEnter.EmptyEnter);
            //pEntity.GetComponent<AIState> ().AddEdge (Round2Idle,EmptyFeedbacker.Run,id_round,id_idle);
            //pEntity.GetComponent<AIState> ().AddEdge (Idle2Round,EmptyFeedbacker.Run,id_idle,id_round);
            pEntity.GetComponent <AIState> ().AddAnimation(Round, "Walk");
            pEntity.GetComponent <AIState> ().AddAnimation(Idle, "Idle");
            pEntity.GetComponent <AIState> ().tempID         = id_round;
            pEntity.GetComponent <AIState> ().mStateRecorder = EmptyExitAndEnter.EmptyEnter;
            if (i == 0)
            {
                GroupManager.getInstance().AddSponsor(pEntity);
            }
            else
            {
                GroupManager.getInstance().AddResponse(pEntity);
            }
        }

        for (int i = 0; i < count1; i++)
        {
            AIEntity pEntity = new AIEntity();
            pEntity.tag = "Test1";
            UEntity mPlayer     = new UEntity();
            UEntity mPlayerLast = new UEntity();
            pEntity.mAI     = groupAICube;
            pEntity.mPlayer = position;
            pEntity.AIPos   = position.transform.position + new Vector3(Random.Range(-20, 20), 0, Random.Range(-20, 20));
            ECSWorld.MainWorld.registerEntityAfterInit(pEntity);
            pEntity.Init();
            pEntity.AddComponent <myAI> (new myAI());
            pEntity.AddComponent <myGroupAI> (new myGroupAI());
            pEntity.GetComponent <BaseAIComponent> ().mAIRT.SetActive(true);
            pEntity.PlayerEntity = mPlayer;

            pEntity.GetComponent <AIAnimation>().mtempAnim = "Walk";
            int id_round = pEntity.GetComponent <AIState> ().AddExecuter(Round, RoundExit, EmptyExitAndEnter.EmptyEnter);

            pEntity.GetComponent <AIState> ().tempID         = id_round;
            pEntity.GetComponent <AIState> ().mStateRecorder = EmptyExitAndEnter.EmptyEnter;

            if (i == 0)
            {
                GroupManager.getInstance().AddSponsor(pEntity);
            }
            else
            {
                GroupManager.getInstance().AddResponse(pEntity);
            }
        }
    }
Beispiel #2
0
    // 群体行为中没有反馈函数

    // Use this for initialization
    void Start()
    {
        enterGroup      = GroupSM4.Enter;
        strategyGroup   = GroupSM4.Strategy;
        allocationGroup = GroupSM4.Allocation;
        dissolveGroup   = GroupSM4.Disslove;
        exitGroup       = GroupSM4.Exit;

        returnEnter    = GroupSM4.Return_Enter;
        returnState    = GroupSM4.Return;
        returnExit     = GroupSM4.Return_Exit;
        roundEnter     = GroupSM4.Round_Enter;
        roundState     = GroupSM4.Round;
        roundExit      = GroupSM4.Round_Exit;
        restEnter      = GroupSM4.Rest_Enter;
        restState      = GroupSM4.Rest;
        restExit       = GroupSM4.Rest_Exit;
        vigilanceEnter = GroupSM4.Vigilance_Enter;
        vigilanceState = GroupSM4.Vigilance;
        vigilanceExit  = GroupSM4.Vigilance_Exit;
        searchEnter    = GroupSM4.Search_Enter;
        searchState    = GroupSM4.Search;
        searchExit     = GroupSM4.Search_Exit;
        chaseEnter     = GroupSM4.Chase_Enter;
        chaseState     = GroupSM4.Chase;
        chaseExit      = GroupSM4.Chase_Exit;
        shieldFEnter   = GroupSM4.ShieldF_Enter;
        shieldFState   = GroupSM4.ShieldF;
        shieldFExit    = GroupSM4.ShieldF_Exit;

        return2round     = GroupSM4.Return2Round;
        round2rest       = GroupSM4.Round2Rest;
        rest2round       = GroupSM4.Rest2Round;
        round2vigilance  = GroupSM4.Round2Vigilance;
        vigilance2round  = GroupSM4.Vigilance2Round;
        rest2vigilance   = GroupSM4.Rest2Vigilance;
        vigilance2search = GroupSM4.Vigilance2Search;
        search2round     = GroupSM4.Serach2Round;
        search2chase     = GroupSM4.Search2Chase;
        chase2round      = GroupSM4.Chase2Round;
        chase2shieldF    = GroupSM4.Chase2ShieldF;
        shieldF2chase    = GroupSM4.ShieldF2Chase;

        GroupBehaviourNode gbnSM4 = new GroupBehaviourNode();

        gbnSM4.mCount    = 4;
        gbnSM4.mRoleName = "ShieldMan";

        List <GroupBehaviourNode> gbnList0 = new List <GroupBehaviourNode> ();

        gbnList0.Add(gbnSM4);

        GroupManager.getInstance().AddGroupList(gbnList0, dissolveGroup, strategyGroup, allocationGroup,
                                                enterGroup, exitGroup);

        AIGroupState aiGroupState0 = new AIGroupState();

        int id0_return    = aiGroupState0.AddGroupState(returnState, returnEnter, returnExit);
        int id0_round     = aiGroupState0.AddGroupState(roundState, roundEnter, roundExit);
        int id0_rest      = aiGroupState0.AddGroupState(restState, restEnter, restExit);
        int id0_vigilance = aiGroupState0.AddGroupState(vigilanceState, vigilanceEnter, vigilanceExit);
        int id0_search    = aiGroupState0.AddGroupState(searchState, searchEnter, searchExit);
        int id0_chase     = aiGroupState0.AddGroupState(chaseState, chaseEnter, chaseExit);
        int id0_shieldF   = aiGroupState0.AddGroupState(shieldFState, shieldFEnter, shieldFExit);

        aiGroupState0.AddAnim(id0_return, GroupSM4.Return_Anim);
        aiGroupState0.AddAnim(id0_round, GroupSM4.Round_Anim);
        aiGroupState0.AddAnim(id0_rest, GroupSM4.Rest_Anim);
        aiGroupState0.AddAnim(id0_vigilance, GroupSM4.Vigilance_Anim);
        aiGroupState0.AddAnim(id0_search, GroupSM4.Search_Anim);
        aiGroupState0.AddAnim(id0_chase, GroupSM4.Chase_Anim);
        aiGroupState0.AddAnim(id0_shieldF, GroupSM4.ShieldF_Anim);


        aiGroupState0.AddTransfer(id0_return, id0_round, return2round);
        aiGroupState0.AddTransfer(id0_round, id0_rest, round2rest);
        aiGroupState0.AddTransfer(id0_rest, id0_round, rest2round);
        aiGroupState0.AddTransfer(id0_round, id0_vigilance, round2vigilance);
        aiGroupState0.AddTransfer(id0_vigilance, id0_round, vigilance2round);
        aiGroupState0.AddTransfer(id0_rest, id0_vigilance, rest2vigilance);
        aiGroupState0.AddTransfer(id0_vigilance, id0_search, vigilance2search);
        aiGroupState0.AddTransfer(id0_search, id0_round, search2round);
        aiGroupState0.AddTransfer(id0_search, id0_chase, search2chase);
        aiGroupState0.AddTransfer(id0_chase, id0_round, chase2round);
        aiGroupState0.AddTransfer(id0_chase, id0_shieldF, chase2shieldF);
        aiGroupState0.AddTransfer(id0_shieldF, id0_chase, shieldF2chase);

        aiGroupState0.tempID = id0_return;

        GroupManager.getInstance().AddStrategy("ShieldMan", 0, aiGroupState0);


        // 二号队伍的绑定
        enterGroup      = GYTGroupSM3TM1.Enter;
        strategyGroup   = GYTGroupSM3TM1.Strategy;
        allocationGroup = GYTGroupSM3TM1.Allocation;
        dissolveGroup   = GYTGroupSM3TM1.Disslove;
        exitGroup       = GYTGroupSM3TM1.Exit;

        returnEnter    = GYTGroupSM3TM1.Return_Enter;
        returnState    = GYTGroupSM3TM1.Return;
        returnExit     = GYTGroupSM3TM1.Return_Exit;
        roundEnter     = GYTGroupSM3TM1.Round_Enter;
        roundState     = GYTGroupSM3TM1.Round;
        roundExit      = GYTGroupSM3TM1.Round_Exit;
        restEnter      = GYTGroupSM3TM1.Rest_Enter;
        restState      = GYTGroupSM3TM1.Rest;
        restExit       = GYTGroupSM3TM1.Rest_Exit;
        vigilanceEnter = GYTGroupSM3TM1.Vigilance_Enter;
        vigilanceState = GYTGroupSM3TM1.Vigilance;
        vigilanceExit  = GYTGroupSM3TM1.Vigilance_Exit;
        searchEnter    = GYTGroupSM3TM1.Search_Enter;
        searchState    = GYTGroupSM3TM1.Search;
        searchExit     = GYTGroupSM3TM1.Search_Exit;
        engageEnter    = GYTGroupSM3TM1.Engage_Enter;
        engageState    = GYTGroupSM3TM1.Engage;
        engageExit     = GYTGroupSM3TM1.Engage_Exit;

        return2round     = GYTGroupSM3TM1.Return2Round;
        round2rest       = GYTGroupSM3TM1.Round2Rest;
        rest2round       = GYTGroupSM3TM1.Rest2Round;
        round2vigilance  = GYTGroupSM3TM1.Round2Vigilance;
        vigilance2round  = GYTGroupSM3TM1.Vigilance2Round;
        rest2vigilance   = GYTGroupSM3TM1.Rest2Vigilance;
        vigilance2search = GYTGroupSM3TM1.Vigilance2Search;
        search2round     = GYTGroupSM3TM1.Serach2Round;
        search2engage    = GYTGroupSM3TM1.Search2Engage;
        engage2return    = GYTGroupSM3TM1.Engage2Return;

        GroupBehaviourNode gbnSM3 = new GroupBehaviourNode();

        gbnSM3.mCount    = 3;
        gbnSM3.mRoleName = "ShieldMan";

        GroupBehaviourNode gbnTM1 = new GroupBehaviourNode();

        gbnTM1.mCount    = 1;
        gbnTM1.mRoleName = "TrapMan";

        List <GroupBehaviourNode> gbnList1 = new List <GroupBehaviourNode> ();

        gbnList1.Add(gbnSM3);
        gbnList1.Add(gbnTM1);

        GroupManager.getInstance().AddGroupList(gbnList1, dissolveGroup, strategyGroup, allocationGroup,
                                                enterGroup, exitGroup);

        AIGroupState aiGroupState1 = new AIGroupState();

        int id1_return    = aiGroupState1.AddGroupState(returnState, returnEnter, returnExit);
        int id1_round     = aiGroupState1.AddGroupState(roundState, roundEnter, roundExit);
        int id1_rest      = aiGroupState1.AddGroupState(restState, restEnter, restExit);
        int id1_vigilance = aiGroupState1.AddGroupState(vigilanceState, vigilanceEnter, vigilanceExit);
        int id1_search    = aiGroupState1.AddGroupState(searchState, searchEnter, searchExit);
        int id1_engage    = aiGroupState1.AddGroupState(engageState, engageEnter, engageExit);

        aiGroupState1.AddAnim(id1_return, GYTGroupSM3TM1.Return_Anim);
        aiGroupState1.AddAnim(id1_round, GYTGroupSM3TM1.Round_Anim);
        aiGroupState1.AddAnim(id1_rest, GYTGroupSM3TM1.Rest_Anim);
        aiGroupState1.AddAnim(id1_vigilance, GYTGroupSM3TM1.Vigilance_Anim);
        aiGroupState1.AddAnim(id1_search, GYTGroupSM3TM1.Search_Anim);
        aiGroupState1.AddAnim(id1_engage, GYTGroupSM3TM1.Engage_Anim);

        aiGroupState1.AddTransfer(id1_return, id1_round, return2round);
        aiGroupState1.AddTransfer(id1_round, id1_rest, round2rest);
        aiGroupState1.AddTransfer(id1_rest, id1_round, rest2round);
        aiGroupState1.AddTransfer(id1_round, id1_vigilance, round2vigilance);
        aiGroupState1.AddTransfer(id1_vigilance, id1_round, vigilance2round);
        aiGroupState1.AddTransfer(id1_rest, id1_vigilance, rest2vigilance);
        aiGroupState1.AddTransfer(id1_vigilance, id1_search, vigilance2search);
        aiGroupState1.AddTransfer(id1_search, id1_round, search2round);
        aiGroupState1.AddTransfer(id1_search, id1_engage, search2engage);
        aiGroupState1.AddTransfer(id1_engage, id1_return, engage2return);

        aiGroupState1.tempID = id1_return;

        GroupManager.getInstance().AddStrategy("TrapMan", 1, aiGroupState1);

        List <int> key0 = new List <int> ();

        key0.Add(0);
        GroupManager.getInstance().AddKey("ShieldMan", key0);

        List <int> key1 = new List <int> ();

        key1.Add(1);
        GroupManager.getInstance().AddKey("TrapMan", key1);

        // 用于设置判定球的半径
        GroupManager.getInstance().mCheckDistance = 20.0f;
    }