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 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 GuidInt(int key) { return (int)LoadValue(typeof(int), "guidItem"+key); } public static void SaveGuidItem(int key,int num) { SaveValue("guidItem" + key, num); } public static int GetItem(int id) { return (ItemDictionary.ContainsKey(id) ? ItemDictionary[id] : 0)+GuidInt(id); //return ItemDatas.FirstOrDefault(vaItemData => vaItemData.item.id == id); } public static void SaveItem(int key, int num) { if (key==0) { return; } if (key==1) { if (num > 30) { num = 30; } } ItemDictionary[key] = num; ItemDictionary = ItemDictionary; } public static void SetTime(string key) { var ts = GetTimeStamp(DateTime.Now.ToUniversalTime()); SaveValue("time" + key, ts); } //获取时间戳 private static int GetTimeStamp(DateTime dt) { TimeSpan ts = dt - new DateTime(1970, 1, 1, 0, 0, 0); return (int)System.Convert.ToInt64(ts.TotalSeconds); } public static void SetDStore(int id,int num) { SetPrefab("storeDay"+id.ToString(),num); } public static int GetDStore(int id) { return GetPrefab("storeDay"+id.ToString()); } public static void SetDDiscount(int id,int dis) { SetPrefab("storeDiscount"+id.ToString(),dis); } public static int GetDDiscount(int id) { return GetPrefab("storeDiscount"+id.ToString()); } //时间戳换算成时间 private static DateTime ConvertIntDatetime(Int64 utc) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1,0,0,0)); startTime = startTime.AddSeconds(utc); return startTime; } public static bool NextDay(string key) { var testTime2 =GetTimeStamp (DateTime.Now); var testTime = GetTimeStamp(GetTime(key)); var testTimeLingchen = testTime - ((testTime + 8 * 3600) % 86400); if (testTime2 > testTime) { if (testTime2 - testTimeLingchen < 24 * 60 * 60) { BDebug.Log("进入时间 和 上次进入时间,在同一天,且在上次进入时间之后"); return false; } else { BDebug.Log("进入时间 和 上次进入时间,不同一天,且在上次进入时间之后"); return true; } } else if (testTime2 < testTime) { if (testTime2 - testTimeLingchen < 24 * 60 * 60) { BDebug.Log("进入时间 和 上次进入时间,在同一天,且在上次进入时间之前"); return false; } else { BDebug.Log("进入时间 和 上次进入时间,不同一天,且在上次进入时间之前"); return false; } } else { BDebug.Log("进入时间 和 上次进入时间,是同一个时刻"); return false; } } public static DateTime GetTime(string key) { return ConvertIntDatetime(GetPrefab("time" + key));; } public static int GetMinute(string key) { TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks - GetTime(key).Ticks); return timeSpan.Minutes; } public static int GetHours(string key) { //计算两个时间间隔 TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks - GetTime(key).Ticks); return timeSpan.Hours; } public static int GetDay(string key) { //计算两个时间间隔 TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks - GetTime(key).Ticks); return timeSpan.Days; } public static int GetPhysical() { AddPhysical(); return GetItem(1); } public static void RemovePhysical() { RemoveItem(1,5); } public static void AddPhysical() { var p = (float)GetMinute("physical")/10; if (p>1) { NewPhysicalEvent(); SetPhysical((int)p); } } public static void NewPhysicalEvent() { SetTime("physical"); } public static void SetPhysical(int i) { var num = GetItem(1) + i; if (num>30) { num = 30; } SaveItem(1, num); } public static void RemovePhysical(int num) { NewPhysicalEvent(); var p = GetItem(1) - num; SaveItem(1 ,p); } /// /// 获取当前图纸等级 /// /// /// public static void SaveDrawLevel(int id,int levelIDd) { SaveValue("Drawing"+id.ToString(), levelIDd); } public static int GetDrawLevel(int id) { return GetPrefab("Drawing" + id.ToString()); } public static void SaveDrawConsumables(int id,int num) { SaveValue("DrawNum"+id,num); } /// /// 图鉴消耗进度 /// /// /// public static int GetDrawConsumables(int id) { return GetPrefab("DrawNum"+id); } public static void SetNowLevel(int level) { SaveValue("Level", level); } public static int GetNowLevel() { return GetPrefab("Level"); } public static void SetLevelLock(int level,bool bo) { SaveValue("LevelLock"+level,bo); } public static bool GetLevelLock(int level) { return (bool)LoadValue(typeof(bool), "LevelLock" + level); } 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, int num, Action action = null) { if (GetItem(id)>=num) { SaveItem(id,GetItem(id)-num); action?.Invoke(true); } else { action?.Invoke(false); } ResetData(); } 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)