/// <summary> /// 读取玩家的核心数据 /// </summary> private void LoadFromXML_PlayerKernalData() { //参数检查 if (string.IsNullOrEmpty(_FileNameByPlayerKernalData)) { Debug.LogError("读取玩家核心参数失败!"); return; } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByPlayerKernalData); //反序列化 Mod_PlayerKernelData pkd = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(Mod_PlayerKernelData)) as Mod_PlayerKernelData; //赋值 Mod_PlayerKernelDataProxy.GetInstance().CurHP = pkd.CurHP; Mod_PlayerKernelDataProxy.GetInstance().MaxHP = pkd.MaxHP; Mod_PlayerKernelDataProxy.GetInstance().CurMP = pkd.CurMP; Mod_PlayerKernelDataProxy.GetInstance().MaxMP = pkd.MaxMP; Mod_PlayerKernelDataProxy.GetInstance().ATK = pkd.ATK; Mod_PlayerKernelDataProxy.GetInstance().DEF = pkd.DEF; Mod_PlayerKernelDataProxy.GetInstance().DEX = pkd.DEX; Mod_PlayerKernelDataProxy.GetInstance().ATKByItem = pkd.ATKByItem; Mod_PlayerKernelDataProxy.GetInstance().DEFByItem = pkd.DEFByItem; Mod_PlayerKernelDataProxy.GetInstance().DEXByItem = pkd.DEXByItem; } catch { Debug.LogError("读取玩家核心参数失败!"); } }
/// <summary> /// 存储玩家的核心数据 /// </summary> private void SaveTOXML_PlayerKernalData() { //数据准备(提取属性数值) float curHP = _PlayerKernelDataProxy.CurHP; float maxHP = _PlayerKernelDataProxy.MaxHP; float curMP = _PlayerKernelDataProxy.CurMP; float maxMP = _PlayerKernelDataProxy.MaxMP; float atk = _PlayerKernelDataProxy.ATK; float atkByItem = _PlayerKernelDataProxy.ATKByItem; float def = _PlayerKernelDataProxy.DEF; float defByItem = _PlayerKernelDataProxy.DEFByItem; float dex = _PlayerKernelDataProxy.DEX; float dexByItem = _PlayerKernelDataProxy.DEXByItem; //实例化类 Mod_PlayerKernelData pkd = new Mod_PlayerKernelData(curHP, curMP, atk, def, dex, maxHP, maxMP, atkByItem, defByItem, dexByItem); //对象序列化 string fileData = XmlOperation.GetInstance().SerializeObject(pkd, typeof(Mod_PlayerKernelData)); //创建XML文件,且写入 if (!String.IsNullOrEmpty(_FileNameByPlayerKernalData)) { XmlOperation.GetInstance().CreateXML(_FileNameByPlayerKernalData, fileData); } }