public static void SaveDifficultyControlDataMap(DifficultyControlDataMap fileDataMap, int gameID, DifficultyControlData fileData) { //Init Data Map if (fileDataMap == null || fileDataMap.MapFileData == null) { fileDataMap = new DifficultyControlDataMap(); fileDataMap.MapFileData = new Dictionary<int, DifficultyControlData>(); } //Init Data if (fileData == null || fileData.DifficultyConfig == null) { fileData = new DifficultyControlData(); fileData.DifficultyConfig = new Dictionary<string, DifficultyConfig>(); } //Save Data if (fileDataMap.MapFileData.ContainsKey(gameID)) { fileDataMap.MapFileData[gameID] = fileData; } else { fileDataMap.MapFileData.Add(gameID, fileData); } //Save File byte[] data = ThriftSerialize.Serialize(fileDataMap); FileUtils.WriteByteFile(GetDifficultyControlDataPath(), data); }
public void Read(TProtocol iprot) { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 10: if (field.Type == TType.Map) { { MapFileData = new Dictionary <int, DifficultyControlData>(); TMap _map15 = iprot.ReadMapBegin(); for (int _i16 = 0; _i16 < _map15.Count; ++_i16) { int _key17; DifficultyControlData _val18; _key17 = iprot.ReadI32(); _val18 = new DifficultyControlData(); _val18.Read(iprot); MapFileData[_key17] = _val18; } iprot.ReadMapEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }
private void Refresh() { m_lstDifficultyInfo = null; // Check File if (m_DifficultyControlDataMap == null || m_DifficultyControlDataMap.MapFileData == null) { return; } if (m_DifficultyControlDataMap.MapFileData.Count <= 0) { return; } // Game Difficulty if (!m_DifficultyControlDataMap.MapFileData.ContainsKey(m_GameID)) { m_DifficultyCount = 0; m_DifficultyLastCount = 0; return; } m_DifficultyControlData = m_DifficultyControlDataMap.MapFileData[m_GameID]; // Difficulty Count m_DifficultyCount = m_DifficultyControlData.DifficultyConfig.Count; m_DifficultyLastCount = m_DifficultyCount; // Editor Data m_lstDifficultyInfo = new List<DifficultyInfo>(); foreach (string diffName in m_DifficultyControlData.DifficultyConfig.Keys) { DifficultyInfo temp = new DifficultyInfo(); temp.Name = diffName; temp.Offset = AdaptiveDifficultyManager.ConvertFloat(m_DifficultyControlData.DifficultyConfig[diffName].DifficultyOffset); temp.Range = AdaptiveDifficultyManager.ConvertFloat(m_DifficultyControlData.DifficultyConfig[diffName].DifficultyRange); Dictionary<string, float> effect = new Dictionary<string, float>(); DefaultUserTalent defaultUserTalent = ConfigManager.Instance.GetDefaultUserTalent(); foreach (string talentName in defaultUserTalent.MapTalent.Keys) { if (m_DifficultyControlData.DifficultyConfig[diffName].TalentEffect.ContainsKey(talentName)) { float effectValue = AdaptiveDifficultyManager.ConvertFloat(m_DifficultyControlData.DifficultyConfig[diffName].TalentEffect[talentName]); effect.Add(talentName, effectValue); } else { effect.Add(talentName, 0f); } } temp.TalentEffects = effect; // add to list m_lstDifficultyInfo.Add(temp); } }
private void SaveFile() { // Save Data m_DifficultyControlData = new DifficultyControlData(); m_DifficultyControlData.DifficultyConfig = new Dictionary<string, DifficultyConfig>(); if (m_lstDifficultyInfo == null) { m_lstDifficultyInfo = new List<DifficultyInfo>(); } for (int i = 0; i < m_lstDifficultyInfo.Count; i++) { if (m_lstDifficultyInfo[i].Name == null || m_lstDifficultyInfo[i].Name == "") { EditorUtility.DisplayDialog("保存失败", "难度名称不能为空", "确定"); return; } DifficultyConfig diffConfig = new DifficultyConfig(); diffConfig.DifficultyOffset = AdaptiveDifficultyManager.ConvertInt(m_lstDifficultyInfo[i].Offset); diffConfig.DifficultyRange = AdaptiveDifficultyManager.ConvertInt(m_lstDifficultyInfo[i].Range); diffConfig.TalentEffect = new Dictionary<string, int>(); foreach (string talent in m_lstDifficultyInfo[i].TalentEffects.Keys) { diffConfig.TalentEffect.Add(talent, AdaptiveDifficultyManager.ConvertInt(m_lstDifficultyInfo[i].TalentEffects[talent])); } m_DifficultyControlData.DifficultyConfig.Add(m_lstDifficultyInfo[i].Name, diffConfig); } //Save File EditorUtility.DisplayDialog("保存成功", "保存成功", "确定"); ADE_Helper.SaveDifficultyControlDataMap(m_DifficultyControlDataMap, m_GameID, m_DifficultyControlData); }