using System; using System.Collections; using System.Collections.Generic; using System.IO; using TTSDK; using TTSDK.UNBridgeLib.LitJson; using UnityEngine; public static class DataManager { public static int Level { get { return GetInt("Level"); } set { SetInt("Level",value); } } public static int chapter { get { return GetInt("chapter"); } set { SetInt("chapter",value); } } public static bool chapterLock(int id) { return GetInt("chapterUnLock"+id)==1; } public static void chapterLock(int id, bool bo) { SetInt("chapterUnLock"+id,bo?1:0); } public static void STTAnalytics(string key,int num) { SetInt("tt" + key, num); } public static int GTTAnalytics(string key) { return GetInt("tt" + key); } private static Dictionary _directory=new Dictionary(); public static bool LevelOpen(int id) { if (_directory.TryGetValue(id, out var open)) return open; var bo = GetInt("level"+id.ToString())==1; if (id==0) { bo = true; } _directory.Add(id,bo); return _directory[id]; } public static void SetLevelOpen(int id,bool bo) { _directory[id] = bo; SetInt("level"+id.ToString(),bo?1:0); } public static int HighestRecordPoints(int id) { return GetInt("HighestPoints"+id); } public static int LastTimePoints(int id) { return GetInt("LastPoints"+id); } public static void SetPointsData(int id, int num) { if (GetInt("HighestPoints"+id) /// 任务数据存储 /// /// /// /// public static void SetTask(int id,int eventID,bool bo) { SetInt(id + "_" + eventID, bo ? 1 : 0); } public static bool GetTask(int id,int eventID) { return GetInt(id + "_" + eventID) == 1; } public static void SaveAllStarNum() { int num = 0; foreach (var bChapter in JsonTab.Instance.tables.Chapter.DataList) { foreach (var levelId in bChapter.Contain) { var lData = JsonTab.Instance.tables.Level.Get(levelId); if (GetTask(lData.ID, lData.Maintasks)) { num++; } foreach (var additionaltask in lData.Additionaltasks) { if (GetTask(lData.ID, additionaltask)) { num++; } } } } SetInt("star", num); } public static int GetStar() { return GetInt("star")-GetSpend(); } public static int GetAllStar() { return GetInt("star"); } public static void SetSpend(int num) { SetInt("Spend",num); } public static int GetSpend() { return GetInt("Spend"); } public static void SetHomeFurnitureID(string key,int id) { SetInt("Furniture-" + key, id); } public static int GetHomeFurnitureID(string key) { return GetInt("Furniture-" + key); } //时间戳换算成时间 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.ToUniversalTime()); var testTime = GetTimeStamp(GetTime(key)); var testTimeLingchen = testTime - ((testTime + 8 * 3600) % 86400); if (testTime2 > testTime) { if (testTime2 - testTimeLingchen < 24 * 60 * 60) { BoxDebug.Log("进入时间 和 上次进入时间,在同一天,且在上次进入时间之后"); return false; } else { BoxDebug.Log("进入时间 和 上次进入时间,不同一天,且在上次进入时间之后"); return true; } } else if (testTime2 < testTime) { if (testTime2 - testTimeLingchen < 24 * 60 * 60) { BoxDebug.Log("进入时间 和 上次进入时间,在同一天,且在上次进入时间之前"); return false; } else { BoxDebug.Log("进入时间 和 上次进入时间,不同一天,且在上次进入时间之前"); return false; } } else { BoxDebug.Log("进入时间 和 上次进入时间,是同一个时刻"); return false; } } public static DateTime GetTime(string key) { return ConvertIntDatetime(GetInt("time" + key));; } public static int GetMinute(string key) { TimeSpan timeSpan = new TimeSpan(DateTimeOffset.Now.Ticks - GetTime(key).Ticks); return (int)timeSpan.TotalMinutes; } public static int GetHours(string key) { //计算两个时间间隔 TimeSpan timeSpan = new TimeSpan(DateTimeOffset.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() { return GetInt("timePhysical"); } public static void AddPhysical() { var p = (float)GetMinute("physical")/10; if (p>1) { NewPhysicalEvent(); SetPhysical((int)p); } } public static void RemovePhysical(int num) { NewPhysicalEvent(); var p = GetInt("timePhysical") - num; SetInt("timePhysical", p); } public static void NewPhysicalEvent() { SetTime("physical"); } public static void SetPhysical(int i) { var num = GetInt("timePhysical") + i; if (num>30) { num = 30; } SetInt("timePhysical", num); } public static void SetTime(string key) { var ts = GetTimeStamp(DateTime.Now.ToUniversalTime()); SetInt("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 SetInt(string key, int num) { TT.PlayerPrefs.SetInt(key, num); } public static int GetInt(string key) { return TT.PlayerPrefs.GetInt(key); } public static void SetString(string key, String num) { PlayerPrefs.SetString(key, num); } public static string GetString(string key) { return PlayerPrefs.GetString(key); } }