/// <summary> /// Reset prefs to initial values /// </summary> public static void ResetValues() { BinaryPrefs.SetDouble(LastDayKey, DateTime.Now.ToOADate()); BinaryPrefs.SetInt(DayCountKey, 1); BinaryPrefs.SetInt(DailySessionCountKey, 1); BinaryPrefs.SetInt(SessionCountKey, 1); }
/// <summary> /// Force Daycount increase in prefs /// </summary> public static void IncreaseDayCount() { BinaryPrefs.SetDouble(LastDayKey, DateTime.Now.ToOADate()); BinaryPrefs.SetInt(DayCountKey, BinaryPrefs.GetInt(DayCountKey) + 1); BinaryPrefs.SetInt(DailySessionCountKey, 1); BinaryPrefs.SetInt(SessionCountKey, BinaryPrefs.GetInt(SessionCountKey) + 1); }
void Start() { //---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------// // BinaryPrefs works like PlayerPrefs: // BinaryPrefs gets values as fast as PlayerPrefs and sets them 40 times faster. // PLAYER PREFS PlayerPrefs.SetInt("testInt", 5); int playerPrefsInt = PlayerPrefs.GetInt("testInt"); // BINARY PREFS BinaryPrefs.SetInt("testInt", 5); int binaryPrefsInt = BinaryPrefs.GetInt("testInt"); //---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------// // BinaryPrefs handles useful types as: BinaryPrefs.SetBool("testBool", true); BinaryPrefs.SetDouble("testDouble", 2.2); //---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------// // BinaryPrefs handles multi-dimensional array serialization: BinaryPrefs.SetClass("testClass", new TwoDimensionArray() { m_Value = new int[, , ] { { { 1, 2, 3, 4 }, { 4, 5, 6, 4 } }, { { 1, 2, 3, 4 }, { 4, 5, 6, 4 } }, }, }); //---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------// // BinaryPrefs is compatible with Json: BinaryPrefs.SetString("testJson", JsonUtility.ToJson(new DataToJson())); //---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------// // BinaryPrefs comes along with useful tools: BinaryPrefs.HasKey("testJson"); BinaryPrefs.DeleteKey("testJson"); BinaryPrefs.ForceSave(); // Use with caution BinaryPrefs.DeleteAll(); // Use with caution //---------------------------------------------------------------------------------// //---------------------------------------------------------------------------------// }
private void Awake() { double lastOADay = BinaryPrefs.GetDouble(LastDayKey); DateTime lastDay = lastOADay == 0.0 ? DateTime.MinValue : DateTime.FromOADate(lastOADay); bool isNextDay = DateTime.Now.Year != lastDay.Year || DateTime.Now.Month != lastDay.Month || DateTime.Now.Day != lastDay.Day; if (lastDay == DateTime.MinValue || isNextDay) { IncreaseDayCount(); } else { BinaryPrefs.SetInt(DailySessionCountKey, BinaryPrefs.GetInt(DailySessionCountKey) + 1); BinaryPrefs.SetInt(SessionCountKey, BinaryPrefs.GetInt(SessionCountKey) + 1); } }