Пример #1
0
        public void SimpleClone(AIGroupState pGroupState)
        {
            Dictionary <int, GroupAnimationRT> mdic = new Dictionary <int, GroupAnimationRT> ();

            foreach (var item in pGroupState.mAnimationDic)
            {
                int ti = item.Key;
                GroupAnimationRT ts = item.Value;
                mdic.Add(ti, ts);
            }
            mAnimationDic   = mdic;
            GroupStateCount = pGroupState.GroupStateCount;
            for (int i = 0; i < GroupStateCount; i++)
            {
                mGroupStateEnters [i] = pGroupState.mGroupStateEnters [i];
                mGroupStateExits [i]  = pGroupState.mGroupStateExits [i];
                mGroupStateRTs [i]    = pGroupState.mGroupStateRTs [i];
            }
            for (int i = 0; i < 30; i++)
            {
                mGroupStateTransfers [i].Clear();
                for (int j = 0; j < pGroupState.mGroupStateTransfers [i].Count; j++)
                {
                    mGroupStateTransfers [i].Add(pGroupState.mGroupStateTransfers[i][j]);
                }
                //Debug.Log (mGroupStateTransfers[i].Count);
            }
            tempID = pGroupState.tempID;
            mGroupStateEnters [tempID] (pLeader, pMembers, tempGroupID);
        }
Пример #2
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            if (!uEntity.GetComponent <AIGroupState> ().isEnable)
            {
                return;
            }
            AIEntity pLeader = uEntity.GetComponent <AIGroupState> ().pLeader;

            AIEntity[] pMembers = uEntity.GetComponent <AIGroupState> ().pMembers;
            int        pid      = uEntity.GetComponent <AIGroupState> ().tempGroupID;

            // check any

            foreach (GroupStateTransferNode gstn in uEntity.GetComponent <AIGroupState>().mGroupStateAnyTransfers)
            {
                if (pid != 0)
                {
                    break;
                }

                int id = gstn.id;
                if (id == uEntity.GetComponent <AIGroupState> ().tempID)
                {
                    continue;
                }
                // update logic
                GroupStateTransfer tTransfer = gstn.mTransfer;
                float rate = tTransfer(pLeader, pMembers, pid);
                if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f))
                {
                    GroupStateExit tExit = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                    tExit(pLeader, pMembers, pid);
                    uEntity.GetComponent <AIGroupState> ().tempID = id;
                    GroupStateEnter tEnter = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                    tEnter(pLeader, pMembers, pid);
                    GroupStateRT ttRT = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID];
                    ttRT(pLeader, pMembers, pid);
                    GroupAnimationRT ttName  = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID];
                    string           ttName_ = ttName(uEntity.GetComponent <AIGroupState>().tempGroupID);
                    uEntity.GetComponent <AIAnimation> ().mtempAnim = ttName_;
                    // async data by leader
                    for (int i = 0; i < pMembers.Length; i++)
                    {
                        GroupStateExit tExit_ = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                        int            pid_   = pMembers [i].GetComponent <AIGroupState> ().tempGroupID;
                        tExit(pLeader, pMembers, pid_);
                        pMembers [i].GetComponent <AIGroupState> ().tempID = id;
                        GroupStateEnter tEnter_ = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                        tEnter_(pLeader, pMembers, pid_);
                        GroupStateRT ttRT_ = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID];
                        ttRT_(pLeader, pMembers, pid_);
                        GroupAnimationRT ttName__  = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID];
                        string           ttName___ = ttName__(pid_);
                        uEntity.GetComponent <AIAnimation> ().mtempAnim = ttName___;
                    }

                    return;
                }
            }

            // check relate

            foreach (GroupStateTransferNode gstn in uEntity.GetComponent <AIGroupState>().mGroupStateTransfers[uEntity.GetComponent <AIGroupState>().tempID])
            {
                if (pid != 0)
                {
                    break;
                }

                int id = gstn.id;
                GroupStateTransfer tTransfer = gstn.mTransfer;
                float rate = tTransfer(pLeader, pMembers, pid);

                if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f))
                {
                    GroupStateExit tExit = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                    tExit(pLeader, pMembers, pid);
                    uEntity.GetComponent <AIGroupState> ().tempID = id;
                    GroupStateEnter tEnter = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                    tEnter(pLeader, pMembers, pid);
                    // async data by leader
                    for (int i = 0; i < pMembers.Length; i++)
                    {
                        GroupStateExit tExit_ = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                        int            pid_   = pMembers [i].GetComponent <AIGroupState> ().tempGroupID;
                        tExit(pLeader, pMembers, pid_);
                        pMembers [i].GetComponent <AIGroupState> ().tempID = id;
                        GroupStateEnter tEnter_ = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                        tEnter_(pLeader, pMembers, pid_);
                    }

                    break;
                }
            }
            // run the Group State node function
            GroupStateRT tRT = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID];

            tRT(pLeader, pMembers, pid);
            GroupAnimationRT tNameRT = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID];
            string           tName   = tNameRT(uEntity.GetComponent <AIGroupState>().tempGroupID);

            uEntity.GetComponent <AIAnimation> ().mtempAnim = tName;
        }
Пример #3
0
 public void AddAnim(int id, GroupAnimationRT name)
 {
     mAnimationDic.Add(id, name);
 }