//在联网前,读取Read本地缓存文件,如果没有文件,hashcode为"",第一行是hashcode //加载Load hashcode,数据,到内存 //登录,比较新hashcode,相同则跳过;不同,则申请新的hashcode //申请的结果和运行时动态更新都是收到服务端的ResponseTextConfig,加载hashcode,数据,到内存,组装新文件替换缓存 /// <summary> /// 从硬盘读取bytes加载到内存。每次刚运行时调用 /// </summary> public static void ReadCacheAndLoadAllLargeConfigs() { for (int i = 0; i < Configs.Length; i++) { var configType = (ConfigType)i; var path = GetFilePath(configType); byte[] bytes = null; if (File.Exists(path)) { try { //bytes = File.ReadAllBytes(path); } catch (Exception e) { Debug.LogException(e); } } if (bytes != null) { IReceiveable configCmd = null; switch (configType) { case ConfigType.CoreConfig: configCmd = new CoreConfig(); break; case ConfigType.RechargeConfig: configCmd = new RechargeConfig(); break; case ConfigType.SkillConfig: configCmd = new SkillConfig(); break; case ConfigType.SkillParameterConfig: configCmd = new SkillParameterConfig(); break; case ConfigType.ExchangeConfig: configCmd = new ExchangeConfig(); break; case ConfigType.VegetableConfig: configCmd = new VegetableConfig(); break; case ConfigType.ChallengeLevelConfig: configCmd = new ChallengeLevelConfig(); break; case ConfigType.SkillIntroTextConfig: configCmd = new SkillIntroTextConfig(); break; case ConfigType.SkillLevelDetailTextConfig: configCmd = new SkillLevelDetailTextConfig(); break; case ConfigType.VegetableIntroTextConfig: configCmd = new VegetableIntroTextConfig(); break; case ConfigType.WaitHintTextConfig: configCmd = new WaitHintTextConfig(); break; case ConfigType.CharacterConfig: configCmd = new CharacterConfig(); break; case ConfigType.EquipConfig: configCmd = new EquipConfig(); break; case ConfigType.MajorLevelIntroTextConfig: configCmd = new MajorLevelIntroTextConfig(); break; case ConfigType.EquipIntroTextConfig: configCmd = new EquipIntroTextConfig(); break; case ConfigType.CharacterIntroTextConfig: configCmd = new CharacterIntroTextConfig(); break; case ConfigType.OAuthParamConfig: configCmd = new OAuthParamConfig(); break; default: Debug.LogError("遇到新的ConfigType,需添加代码。type:" + configType); break; } if (configCmd != null) { configCmd.ParseFrom(bytes); SetConfig(configType, configCmd); } } } }
private void UpperSetAndRefresh(int index) { LblLevel.text = string.Format("{0}", CommonData.MyUser.Level); LblExp.text = string.Format("{0}/{1}", CommonData.MyUser.Exp, CommonData.MyUser.ExpCeil); SldExp.value = 1f * CommonData.MyUser.Exp / CommonData.MyUser.ExpCeil; var attack = 0; var health = CommonData.MyUser.RoundInitHealth; var equipConfig = ConfigManager.GetConfig(ConfigManager.ConfigType.EquipConfig) as EquipConfig; if (equipConfig != null) { var myUserCharacter = CommonData.MyCharacterList.Find(x => x.CharacterCode == CommonData.MyUser.CharacterCode); if (myUserCharacter != null) { foreach (var equip in myUserCharacter.WearEquipList.Select(equipCode => equipConfig.EquipList.Find(x => x.EquipCode == equipCode)).Where(equip => equip != null)) { attack += (int)equip.AttackAdd; health += (int)equip.HealthAdd; MyCharacter.WearEquip(equip.Type, equip.EquipCode);//角色穿装备 } } } LblAttack.text = attack.ToString(); LblDefense.text = health.ToString(); if (_characterList.Count == 0) { Debug.LogError("_characterList.Count == 0 ERROR"); return; } if (_equipConfig == null) { return; } _index = Mathf.Clamp(index, 0, _characterList.Count - 1); MyCharacter.CharacterCode = CurCharacterCode; MyCharacter.Refresh(); MyCharacter.TakeOffAllEquip(); var sprs = MyCharacter.GetComponentsInChildren <SpriteRenderer>(true); foreach (var spriteRenderer in sprs) { spriteRenderer.sortingLayerName = "Foreground"; } var curUserCharacter = CommonData.MyCharacterList.Find(x => x.CharacterCode == CurCharacterCode); if (curUserCharacter == null) //未解锁 { GrpLockedCharacter.SetActive(true); GrpUnlockedCharacter.SetActive(false); if (_characterIntroTextConfig == null) { _characterIntroTextConfig = ConfigManager.GetConfig(ConfigManager.ConfigType.CharacterIntroTextConfig) as CharacterIntroTextConfig; } if (_characterIntroTextConfig != null) { var intro = _characterIntroTextConfig.IntroList.Find(x => x.CharacterCode == CurCharacterCode); if (intro != null) { LblCharacterDescription.text = intro.Description; LblCharacterTalent.text = intro.TalentIntro; } else { Debug.LogError("没有CharacterIntro。Code:" + CurCharacterCode); LblCharacterDescription.text = null; LblCharacterTalent.text = null; } } else { Debug.LogError("没有CharacterIntroTextConfig"); LblCharacterDescription.text = null; LblCharacterTalent.text = null; } } else//已解锁 { GrpUnlockedCharacter.SetActive(true); GrpLockedCharacter.SetActive(false); //出战按钮 if (CommonData.MyUser.CharacterCode == CurCharacterCode) { BtnChuzhan.isEnabled = false; Tick.enabled = true; } else { BtnChuzhan.isEnabled = true; Tick.enabled = false; } for (int type = 0; type < 5; type++) { SprEquips[type].enabled = false; } foreach (var code in curUserCharacter.WearEquipList) { var equip = _equipConfig.EquipList.Find(x => x.EquipCode == code); if (equip == null) { Debug.LogError("找不到配置Equip:" + code); continue; } var type = equip.Type; SprEquips[type].atlas = MorlnDownloadResources.Load <UIAtlas>("ResourcesForDownload/Equip/EquipIcon/Atlas-EquipIcons"); var sprName = EquipUtil.GetEquipSpriteName(code, type); //var spr = Resources.Load<Sprite>("Sprites/Equip/" + sprName); SprEquips[type].enabled = true; //SprEquips[type].sprite = spr; SprEquips[type].spriteName = sprName; MyCharacter.WearEquip(type, code); } } BtnLeft.SetActive(_index > 0); BtnRight.SetActive(_index < _characterList.Count - 1); }