// Use this for initialization void Start() { if (instance == null) //Singleton { instance = GetComponent <StageTempData>(); DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
// 服务器同步角色关卡数据 public void onSyncStageData(EventBase e) { PlayerDataModule module = ModuleManager.Instance.FindModule <PlayerDataModule>(); ClearZoneStarNum(); mUnlockDatas = new Dictionary <ConditionType, ArrayList>(); Dictionary <SceneType, Dictionary <int, ZoneTempData> > mTempDatas = new Dictionary <SceneType, Dictionary <int, ZoneTempData> >(); System.Type type = typeof(Scene_StageSceneTableItem); IDictionaryEnumerator itr = DataManager.Scene_StageSceneTable.GetEnumerator(); while (itr.MoveNext()) { Scene_StageSceneTableItem res = itr.Value as Scene_StageSceneTableItem; ConditionTableItem condres = null; for (uint i = 0; i < Scene_StageSceneTableItem.MAX_UNLOCK_CONDITION_COUNT; ++i) { // 建立解锁条件->解锁关卡id的映射 System.Reflection.FieldInfo fieldid = type.GetField("mUnlockCondId" + i.ToString()); int unlockcondid = (int)fieldid.GetValue(res); if (unlockcondid >= 0 && DataManager.ConditionTable.ContainsKey(unlockcondid)) { ConditionTableItem condtableres = DataManager.ConditionTable[unlockcondid] as ConditionTableItem; ArrayList unlocklist = null; if (mUnlockDatas.ContainsKey(condtableres.mType)) { unlocklist = mUnlockDatas[condtableres.mType]; } if (unlocklist == null) { unlocklist = new ArrayList(); mUnlockDatas.Add(condtableres.mType, unlocklist); } StageUnlockData unlockdata = new StageUnlockData(); unlockdata.condition = condtableres; unlockdata.stageid = res.resID; unlocklist.Add(unlockdata); if (condtableres.mType == ConditionType.STAGE_GRADE) { condres = condtableres; } } } // 战区星星数 if (module.IsStageHasPassed(res.resID) && mSubTypeDatas.ContainsKey(SceneManager.GetSceneType(res))) { Dictionary <int, StageFightZone> zonedata = mSubTypeDatas[SceneManager.GetSceneType(res)].mFightZoneDatas; if (zonedata != null && zonedata.ContainsKey(res.mZoneId)) { zonedata[res.mZoneId].mStarNum++; } } // 按解锁关系排序 Dictionary <int, ZoneTempData> tempSubTypeData = null; if (mTempDatas.ContainsKey(SceneManager.GetSceneType(res))) { tempSubTypeData = mTempDatas[SceneManager.GetSceneType(res)]; } if (tempSubTypeData == null) { tempSubTypeData = new Dictionary <int, ZoneTempData>(); mTempDatas.Add(SceneManager.GetSceneType(res), tempSubTypeData); } ZoneTempData tempZoneData = null; if (tempSubTypeData.ContainsKey(res.mZoneId)) { tempZoneData = tempSubTypeData[res.mZoneId]; } if (tempZoneData == null) { tempZoneData = new ZoneTempData(); tempSubTypeData.Add(res.mZoneId, tempZoneData); } if (tempZoneData.mStageTempDatas == null) { tempZoneData.mStageTempDatas = new Dictionary <int, StageTempData>(); } StageTempData temp = new StageTempData(); temp.stageId = res.resID; if (condres != null) { temp.prevStageId = condres.mParam1; } else { temp.prevStageId = -1; if (!tempZoneData.mHeadStageIdList.Contains(res.resID)) { tempZoneData.mHeadStageIdList.Add(res.resID); } //tempZoneData.mHeadStageId = res.resID; } tempZoneData.mStageTempDatas.Add(res.resID, temp); } // foreach (Scene_StageSceneTableItem res in DataManager.Scene_StageSceneTable.Values) // { // // } foreach (SceneType subtype in mTempDatas.Keys) { if (!mSubTypeDatas.ContainsKey(subtype)) { continue; } StageSubTypeData subtypedata = mSubTypeDatas[subtype]; Dictionary <int, ZoneTempData> tempsubdata = mTempDatas[subtype]; foreach (int zoneid in tempsubdata.Keys) { if (!subtypedata.mFightZoneDatas.ContainsKey(zoneid)) { continue; } StageFightZone fightzonedata = subtypedata.mFightZoneDatas[zoneid]; fightzonedata.mStageListIds = new ArrayList(); ZoneTempData tempzonedata = tempsubdata[zoneid]; foreach (StageTempData tempstagedata in tempzonedata.mStageTempDatas.Values) { if (tempstagedata.prevStageId < 0 || !tempzonedata.mStageTempDatas.ContainsKey(tempstagedata.prevStageId)) { continue; } tempzonedata.mStageTempDatas[tempstagedata.prevStageId].nextStageId = tempstagedata.stageId; } for (int i = 0; i < tempzonedata.mHeadStageIdList.Count; ++i) { int headId = tempzonedata.mHeadStageIdList[i]; if (!tempzonedata.mStageTempDatas.ContainsKey(headId)) { continue; } fightzonedata.mStageListIds.Add(headId); } for (int i = 0; i < tempzonedata.mHeadStageIdList.Count; ++i) { int headId = tempzonedata.mHeadStageIdList[i]; if (!tempzonedata.mStageTempDatas.ContainsKey(headId)) { continue; } StageTempData curdata = tempzonedata.mStageTempDatas[headId]; if (curdata == null) { continue; } if (!tempzonedata.mStageTempDatas.ContainsKey(curdata.nextStageId)) { continue; } StageTempData nextdata = tempzonedata.mStageTempDatas[curdata.nextStageId]; do { fightzonedata.mStageListIds.Add(nextdata.stageId); nextdata = tempzonedata.mStageTempDatas.ContainsKey(nextdata.nextStageId) ? tempzonedata.mStageTempDatas[nextdata.nextStageId] : null; } while (nextdata != null); } } } }