/// <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); } }
/// <summary> /// 读取玩家核心数据 /// </summary> private PlayerProperty ReadFromXML_PlayerInfoData() { PlayerProperty pkd = null; //参数检查 if (string.IsNullOrEmpty(_FileNameByKernalData)) { Debug.LogError(GetType() + "/ReadFromXML_GlobalParaData()/_FileNameByKernalData is Null!!!"); return(null); } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByKernalData); //反序列化 pkd = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(PlayerProperty)) as PlayerProperty; //赋值 } catch { Debug.LogError(GetType() + "/ReadFromXML_PlayerKernalData()/读取游戏的核心参数,不成功,请检查"); } return(pkd); }
/// <summary> /// 读玩家背包数据 /// </summary> private List <InventoryItem> ReadFromXML_InventoryData() { List <InventoryItem> itemlist = new List <InventoryItem>(); //参数检查 if (string.IsNullOrEmpty(_FileNameByPackageData)) { Debug.LogError(GetType() + "/ReadFromXML_PlayerPackageData()/_FileNameByPackageData is Null!!!"); return(null); } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByPackageData); string[] items = strTemp.Split('|'); for (int i = 0; i < items.Length; i++) { InventoryItem item = new InventoryItem(); //反序列化 item = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(InventoryItem)) as InventoryItem; itemlist.Add(item); } } catch { Debug.LogError(GetType() + "/ReadFromXML_PlayerPackageData()/读取游戏的背包参数,不成功,请检查"); } return(itemlist); }
/// <summary> /// 读取玩家的扩展数据 /// </summary> private void LoadFromXML_PlayerExtendedData() { //参数检查 if (string.IsNullOrEmpty(_FileNameByPlayerExtendedData)) { Debug.LogError("读取玩家扩展参数失败!"); return; } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByPlayerExtendedData); //反序列化 Mod_PlayerExtendedData ped = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(Mod_PlayerExtendedData)) as Mod_PlayerExtendedData; //赋值 Mod_PlayerExtendedDataProxy.GetInstance().EXP = ped.EXP; Mod_PlayerExtendedDataProxy.GetInstance().KillNum = ped.KillNum; Mod_PlayerExtendedDataProxy.GetInstance().Level = ped.Level; Mod_PlayerExtendedDataProxy.GetInstance().Gold = ped.Gold; Mod_PlayerExtendedDataProxy.GetInstance().Diamond = ped.Diamond; } catch { Debug.LogError("读取玩家扩展参数失败!"); } }
/// <summary> /// 读取游戏的全局参数 /// </summary> private void ReadFromXML_GlobalParaData() { GlobalParametersData dpd = null; //参数检查 if (string.IsNullOrEmpty(_FileNameByGlobalParameterData)) { Debug.LogError(GetType() + "/ReadFromXML_GlobalParaData()/_FileNameByGlobalParameterData is Null!!!"); return; } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByGlobalParameterData); //反序列化 dpd = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(GlobalParametersData)) as GlobalParametersData; //赋值 GlobalParametersManager.CurrentPlayerName = dpd.PlayerName; GlobalParametersManager.NextSceneTYPE = dpd.NextScenesName; // GlobalParametersManager.= CurrentGameType.Continue; } catch { Debug.LogError(GetType() + "/ReadFromXML_GlobalParaData()/读取游戏的全局参数,不成功,请检查"); } }
//load player inventory datas private void ReadFromXML_PlayerInventoryData() { PlayerInventoryData PID = null; if (string.IsNullOrEmpty(_FileNameByInventoryData)) { Debug.LogError(GetType() + "/ReadFromXML_PlayerInventoryData()/_FileNameByInventoryData doesn't exist"); return; } try { //load xml string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByExtendalData); PID = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(PlayerInventoryData)) as PlayerInventoryData; PlayerInventoryDataProxy.GetInstance().HealthPotionNum = PID.HealthPotionNum; PlayerInventoryDataProxy.GetInstance().ManaPotionNum = PID.ManaPotionNum; PlayerInventoryDataProxy.GetInstance().PropATKNum = PID.PropATKNum; PlayerInventoryDataProxy.GetInstance().PropDEFNum = PID.PropDEFNum; PlayerInventoryDataProxy.GetInstance().PropDEXNum = PID.PropDEXNum; } catch { Debug.LogError(GetType() + "/ReadFromXML_PlayerInventoryData()/load game save config data failed"); } }
//load player extenal datas private void ReadFromXML_PlayerExtenalData() { PlayerExtenalData PED = null; if (string.IsNullOrEmpty(_FileNameByExtendalData)) { Debug.LogError(GetType() + "/ReadFromXML_PlayerExtenalData()/_FileNameByExtendalData doesn't exist"); return; } try { //load xml string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByExtendalData); PED = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(PlayerExtenalData)) as PlayerExtenalData; PlayerExtenalDataProxy._Instance.Experience = PED.Experience; PlayerExtenalDataProxy._Instance.KillNumber = PED.KillNumber; PlayerExtenalDataProxy._Instance.Level = PED.Level; PlayerExtenalDataProxy._Instance.Gold = PED.Gold; PlayerExtenalDataProxy._Instance.Diamonds = PED.Diamonds; } catch { Debug.LogError(GetType() + "/ReadFromXML_PlayerExtenalData()/load game save config data failed"); } }
/// <summary> /// 读取玩家的背包数据 /// </summary> private void LoadFromXML_PlayerPackageData() { //参数检查 if (string.IsNullOrEmpty(_FileNameByPlayerPackageData)) { Debug.LogError("读取玩家背包页面参数失败!"); return; } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByPlayerPackageData); //反序列化 Mod_PlayerPackageData ppd = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(Mod_PlayerPackageData)) as Mod_PlayerPackageData; //赋值 Mod_PlayerPackageDataProxy.GetInstance().Item_Weapon_1.Count = ppd.Item_Weapon_1.Count; Mod_PlayerPackageDataProxy.GetInstance().Item_Shield_1.Count = ppd.Item_Shield_1.Count; Mod_PlayerPackageDataProxy.GetInstance().Item_Boot_1.Count = ppd.Item_Boot_1.Count; Mod_PlayerPackageDataProxy.GetInstance().Item_HPPotion_1.Count = ppd.Item_HPPotion_1.Count; Mod_PlayerPackageDataProxy.GetInstance().Item_MPPotion_1.Count = ppd.Item_MPPotion_1.Count; } catch { Debug.LogError("读取玩家背包页面参数失败!"); } }
//load game config private void ReadFromXML_GlobalParaData() { GlobalParameterData GPD = null; if (string.IsNullOrEmpty(_FileNameByGlobalParameterData)) { Debug.LogError(GetType() + "/ReadFromXML_GlobalParaData()/_FileNameByGlobalParameterData doesn't exist"); return; } try { //load xml string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByGlobalParameterData); GPD = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(GlobalParameterData)) as GlobalParameterData; GlobalParaMgr.PlayerName = GPD.PlayerName; GlobalParaMgr.NextScenesName = GPD.NextScenesName; GlobalParaMgr.CurGameType = CurrentGameType.Continue; } catch { Debug.LogError(GetType() + "/ReadFromXML_GlobalParaData()/load game save config data failed"); } }
/// <summary> /// 读取游戏的全局参数 /// </summary> private void LoadFromXML_GlobalParameterData() { //参数检查 if (string.IsNullOrEmpty(_FileNameByGlobalParameterData)) { Debug.LogError("读取游戏全局参数失败!"); return; } try { //读取XML数据 string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByGlobalParameterData); //反序列化 Mod_GlobalParaData dpd = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(Mod_GlobalParaData)) as Mod_GlobalParaData; //赋值 GlobalParaMgr.PlayerName = dpd.PlayerName; GlobalParaMgr.NextSceneName = dpd.NextSceneName; GlobalParaMgr.CurPlayerType = dpd.PlayerType; if (GlobalParaMgr.CurGameStatus != GameStatus.Continue) { GlobalParaMgr.CurGameStatus = GameStatus.Continue; } } catch { Debug.LogError("读取游戏全局参数失败!"); } }
//存储玩家核心数据 private void StoreTOXML_PlayerInfoData() { //数据准备 PlayerProperty playerInfoData = PlayerInfo.Instance.PlayerPropertyCurrent; //对象序列化[对这个文件做字符串处理写入xml] string s = XmlOperation.GetInstance().SerializeObject(playerInfoData, typeof(PlayerProperty)); //创建XML文件,且写入[保证文件不为空写入] if (string.IsNullOrEmpty(_FileNameByKernalData)) { XmlOperation.GetInstance().CreateXML(_FileNameByKernalData, s); } }
//存储游戏全局参数 private void StoreTOXML_GlobalParametersData() { string playerName = GlobalParametersManager.CurrentPlayerName; SceneType scenesName = GlobalParametersManager.NextSceneTYPE; GlobalParametersData GPD = new GlobalParametersData(scenesName, playerName); //对象序列化 string s = XmlOperation.GetInstance().SerializeObject(GPD, typeof(GlobalParametersData)); //创建XML文件,且写入[保证文件不为空写入] if (string.IsNullOrEmpty(_FileNameByGlobalParameterData)) { XmlOperation.GetInstance().CreateXML(_FileNameByGlobalParameterData, s); } Log.Write(GetType() + "/ StoreTOXML_GlobalParaData()/xml Path =" + _FileNameByGlobalParameterData, LevelType.Special); }
//存储玩家背包数据 private void StoreTOXML_InventoryData() { //数据准备 string s = ""; for (int i = 0; i < InventoryUIManager.Instance.InventoryItemList.Count; i++) { s += XmlOperation.GetInstance().SerializeObject(InventoryUIManager.Instance.InventoryItemList[i], typeof(InventoryItem)) + "|"; } s.Substring(0, s.Length - 1); //对象序列化 //创建XML文件,且写入[保证文件不为空写入] if (string.IsNullOrEmpty(_FileNameByPackageData)) { XmlOperation.GetInstance().CreateXML(_FileNameByPackageData, s); } }
//save game config private void StoreTOXML_GlobalParaData() { string playerName = GlobalParaMgr.PlayerName; ScenesEnum scenesName = GlobalParaMgr.NextScenesName; GlobalParameterData GPD = new GlobalParameterData(scenesName, playerName); //Object serialization string s = XmlOperation.GetInstance().SerializeObject(GPD, typeof(GlobalParameterData)); //create xml file, and save data to this xml file if (!string.IsNullOrEmpty(_FileNameByGlobalParameterData)) { XmlOperation.GetInstance().CreateXML(_FileNameByGlobalParameterData, s); } Log.Write(GetType() + "StoreTOXML_GlobalParaData()/ xml path =" + _FileNameByGlobalParameterData); }
/// <summary> /// 存储游戏的全局参数 /// </summary> private void SaveToXML_GlobalParameterData() { //提取属性数值 //这里的局部变量类型可以全部统一使用var SceneEnum sceneName = GlobalParaMgr.NextSceneName; string playerName = GlobalParaMgr.PlayerName; PlayerType playerType = GlobalParaMgr.CurPlayerType; //实例化类 Mod_GlobalParaData gpd = new Mod_GlobalParaData(sceneName, playerName, playerType); //对象序列化 string fileData = XmlOperation.GetInstance().SerializeObject(gpd, typeof(Mod_GlobalParaData)); //创建XML文件,且写入 if (!String.IsNullOrEmpty(_FileNameByGlobalParameterData)) { XmlOperation.GetInstance().CreateXML(_FileNameByGlobalParameterData, fileData); } }
/// <summary> /// 存储玩家的扩展数据 /// </summary> private void SaveToXML_PlayerExtendedData() { //数据准备(提取属性数值) int exp = _PlayerExtendedDataProxy.EXP; int killNum = _PlayerExtendedDataProxy.KillNum; int level = _PlayerExtendedDataProxy.Level; int gold = _PlayerExtendedDataProxy.Gold; int diamond = _PlayerExtendedDataProxy.Diamond; //实例化类 Mod_PlayerExtendedData ped = new Mod_PlayerExtendedData(exp, killNum, level, gold, diamond); //对象序列化 string fileData = XmlOperation.GetInstance().SerializeObject(ped, typeof(Mod_PlayerExtendedData)); //创建XML文件,且写入 if (!String.IsNullOrEmpty(_FileNameByPlayerExtendedData)) { XmlOperation.GetInstance().CreateXML(_FileNameByPlayerExtendedData, fileData); } }
/// <summary> /// 存储玩家的背包数据 /// </summary> private void SaveToXML_PlayerPackageData() { //数据准备(提取属性数值) int weapon_1_Count = _PlayerPackageDataProxy.Item_Weapon_1.Count; int shield_1_Count = _PlayerPackageDataProxy.Item_Shield_1.Count; int boot_1_Count = _PlayerPackageDataProxy.Item_Boot_1.Count; int hpPotion_1_Count = _PlayerPackageDataProxy.Item_HPPotion_1.Count; int mpPotion_1_Count = _PlayerPackageDataProxy.Item_MPPotion_1.Count; //实例化类 Mod_PlayerPackageData ppd = new Mod_PlayerPackageData(weapon_1_Count, shield_1_Count, boot_1_Count, hpPotion_1_Count, mpPotion_1_Count); //对象序列化 string fileData = XmlOperation.GetInstance().SerializeObject(ppd, typeof(Mod_PlayerPackageData)); //创建XML文件,且写入 if (!String.IsNullOrEmpty(_FileNameByPlayerPackageData)) { XmlOperation.GetInstance().CreateXML(_FileNameByPlayerPackageData, fileData); } }
//save player extenal data private void StoreTOXML_ExtenalData() { int exp = _PlayerExtenalDataProxy.Experience; int killNum = _PlayerExtenalDataProxy.KillNumber; int level = _PlayerExtenalDataProxy.Level; int glod = _PlayerExtenalDataProxy.Gold; int diamond = _PlayerExtenalDataProxy.Diamonds; PlayerExtenalData PED = new PlayerExtenalData(exp, killNum, level, glod, diamond); //Object serialization string s = XmlOperation.GetInstance().SerializeObject(PED, typeof(GlobalParameterData)); //create xml file, and save data to this xml file if (!string.IsNullOrEmpty(_FileNameByExtendalData)) { XmlOperation.GetInstance().CreateXML(_FileNameByExtendalData, s); } Log.Write(GetType() + "StoreTOXML_ExtenalData()/ xml path =" + _FileNameByExtendalData); }
//save player inventory data private void StoreTOXML_InventoryData() { int HP = _PlayerInventoryDataProxy.HealthPotionNum; int MP = _PlayerInventoryDataProxy.ManaPotionNum; int ATKItem = _PlayerInventoryDataProxy.PropATKNum; int DEFItem = _PlayerInventoryDataProxy.PropDEFNum; int DEXItem = _PlayerInventoryDataProxy.PropDEXNum; PlayerInventoryDataProxy PIDP = new PlayerInventoryDataProxy(HP, MP, ATKItem, DEFItem, DEXItem); //Object serialization string s = XmlOperation.GetInstance().SerializeObject(PIDP, typeof(GlobalParameterData)); //create xml file, and save data to this xml file if (!string.IsNullOrEmpty(_FileNameByInventoryData)) { XmlOperation.GetInstance().CreateXML(_FileNameByInventoryData, s); } Log.Write(GetType() + "StoreTOXML_InventoryData()/ xml path =" + _FileNameByInventoryData); }
//load player core datas private void ReadFromXML_PlayerKernalData() { PlayerSaveData PSD = null; if (string.IsNullOrEmpty(_FileNameByKernalData)) { Debug.LogError(GetType() + "/ReadFromXML_PlayerKernalData()/_FileNameByKernalData doesn't exist"); return; } try { //load xml string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByKernalData); PSD = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(PlayerSaveData)) as PlayerSaveData; PlayerSaveDataProxy._Instance.Health = PSD.Health; PlayerSaveDataProxy._Instance.Magic = PSD.Magic; PlayerSaveDataProxy._Instance.Attack = PSD.Attack; PlayerSaveDataProxy._Instance.Defence = PSD.Defence; PlayerSaveDataProxy._Instance.Dexterity = PSD.Dexterity; PlayerSaveDataProxy._Instance.MaxHealth = PSD.MaxHealth; PlayerSaveDataProxy._Instance.MaxMagic = PSD.MaxMagic; PlayerSaveDataProxy._Instance.MaxAttack = PSD.MaxAttack; PlayerSaveDataProxy._Instance.MaxDefence = PSD.MaxDefence; PlayerSaveDataProxy._Instance.MaxDexterity = PSD.MaxDexterity; PlayerSaveDataProxy._Instance.AttackByProp = PSD.AttackByProp; PlayerSaveDataProxy._Instance.DefenceByProp = PSD.DefenceByProp; PlayerSaveDataProxy._Instance.DexterityByProp = PSD.DexterityByProp; } catch { Debug.LogError(GetType() + "/ReadFromXML_PlayerKernalData()/load game save config data failed"); } }
//save player core data private void StoreTOXML_KernalData() { //data that need to be save to xml file float health = _PlayerKernalDataProxy.Health; float magic = _PlayerKernalDataProxy.Magic; float attack = _PlayerKernalDataProxy.Attack; float defence = _PlayerKernalDataProxy.Defence; float dexterity = _PlayerKernalDataProxy.Dexterity; float maxHealth = _PlayerKernalDataProxy.MaxHealth; float maxMagic = _PlayerKernalDataProxy.MaxMagic; float maxAttack = _PlayerKernalDataProxy.MaxAttack; float maxDefence = _PlayerKernalDataProxy.MaxDefence; float maxDexterity = _PlayerKernalDataProxy.MaxDexterity; float attaclItem = _PlayerKernalDataProxy.AttackByProp; float defenceItem = _PlayerKernalDataProxy.DefenceByProp; float dexterityItem = _PlayerKernalDataProxy.DexterityByProp; PlayerSaveData PSD = new PlayerSaveData( health, magic, attack, defence, dexterity, maxHealth, maxMagic, maxAttack, maxDefence, maxDexterity, attaclItem, defenceItem, dexterityItem ); //Object serialization string s = XmlOperation.GetInstance().SerializeObject(PSD, typeof(GlobalParameterData)); //create xml file, and save data to this xml file if (!string.IsNullOrEmpty(_FileNameByKernalData)) { XmlOperation.GetInstance().CreateXML(_FileNameByKernalData, s); } Log.Write(GetType() + "StoreTOXML_KernalData()/ xml path =" + _FileNameByKernalData); }