public override void saveData() { DataForNPC npcdata = new DataForNPC(); npcdata.Path = Operator.DataAssets.Path; npcdata.CurrentHealth = CurrentHealth; npcdata.TotalHealth = TotalHealth; npcdata.CurrentEnergy = CurrentEnergy; npcdata.TotalEnergy = TotalEnergy; npcdata.Coins = Coins; // 清除物品索引列表 npcdata.ItemReference.Clear(); // 更新物品索引列表 for (int i = 0; i < ItemList.Count; i++) { npcdata.addItemIndex(ItemList[i].ID, Bag.findItemGrid(ItemList[i]).ItemCount, ItemList[i].getStatus()); } // 更新DataAssets Operator.DataAssets = npcdata; Operator.saveData(); print("SaveData|Path:" + Operator.DataAssets.Path); #if UNITY_EDITOR #else try { MessageBoard.Instance.generateMessage("Save Data..."); } catch (Exception e) { print(e.Message); } #endif }
public override void loadData() { // 声明临时变量存放数据 Data data = new Data(); DataForNPC npcdata = new DataForNPC(); // 从DataAssets获取数据至playerdata Operator.loadData(out data); npcdata = (DataForNPC)data; // 同步数据至人物 TotalHealth = npcdata.TotalHealth; CurrentHealth = npcdata.CurrentHealth; TotalEnergy = npcdata.TotalEnergy; CurrentEnergy = npcdata.CurrentEnergy; Coins = npcdata.Coins; ItemReference = npcdata.ItemReference; if (CurrentHealth <= 0) { LoadObj.SetActive(false); } // 清空背包 Bag.clearItem(); // 更新背包 Bag.LoadMode = true; for (int i = 0; i < npcdata.ItemReference.Count; i++) { Bag.addItem(ItemStock.Instance.getItemByID(npcdata.ItemReference[i].ID), npcdata.ItemReference[i].Count); } Bag.LoadMode = false; Operator.DataAssets.Path = Application.dataPath + "/Save/" + CharacterName + "Data.txt"; }