using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEditor; using UnityEngine; public static class DataManager { public static List ItemDatas; public static bool GetFirst() { return GetPrefab("First")==1; } public static void SaveFirst() { SetPrefab("First",1); } public static Dictionary ItemDictionary { get { if (itemDictionary==null) { itemDictionary = (Dictionary)LoadValue(typeof(Dictionary), "ItemDic"); } return itemDictionary; } set { BDebug.Log(value); itemDictionary = value; SaveValue("ItemDic", itemDictionary); } } private static Dictionary itemDictionary; public static int GetItem(int id) { return ItemDictionary.ContainsKey(id) ? ItemDictionary[id] : 0; //return ItemDatas.FirstOrDefault(vaItemData => vaItemData.item.id == id); } public static void SaveItem(int key, int num) { ItemDictionary[key] = num; ItemDictionary = ItemDictionary; } public static void SaveItemUnLock(int key,bool bo) { SetPrefab("item-"+key,bo?1:0); } public static bool GetItemUnLock(int key) { return GetPrefab("item-"+key)==1; } public static void AddItem(int id, int itemNum) { SaveItem(id, GetItem(id) + itemNum); // if (ItemDatas==null) // { // ItemDatas = new List(); // } // var listData = ItemDatas.FirstOrDefault(vaItemData => vaItemData.item.id == itemData.id); // if (listData==null) // { // ItemData saveData = new ItemData(itemData, itemNum); // ItemDatas.Add(saveData); // } // else // { // listData.num += itemNum; // } } public static void RemoveItem(int id,Action action) { if (GetItem(id)>=1) { SaveItem(id,GetItem(id)-1); action.Invoke(true); } else { action.Invoke(false); } ResetData(); } public static void RemoveItem(List itemDatas,Action action) { foreach (var data in itemDatas) { if (GetItem(data.id)