void OnGetLiveTime(DateTime?dateTime) { if (dateTime == null) { Debug.LogError("Unable to get live datetime"); } DataHelper.Instance.CheckDailyEntrance(dateTime); int dayNum = GameSaveData.GetDailyEntranceNumber(); if (DataHelper.Instance.DailyEntranceDisturbed) { } StartCoroutine(_GoToMenu()); }
public void CheckDailyEntrance(DateTime?nowDateTime) { DailyEntrance = false; if (nowDateTime != null) { var str = GameSaveData.GetLastDailyEntranceDate(); if (str != string.Empty) { var jsonObj = JSONObject.Create(str); int year = (int)jsonObj["year"].i; int month = (int)jsonObj["month"].i; int day = (int)jsonObj["day"].i; var date = new DateTime(year, month, day, 0, 0, 0, 0); var diff = nowDateTime.Value - date; if (diff.TotalSeconds > 0) { if (diff.TotalHours < 24) { DailyEntrance = true; } else { GameSaveData.SetDailyEntranceNumber(0); } } } //Calculate next daily entrance { var today = nowDateTime.Value; int year = today.Year, month = today.Month, day = today.Day; if (day < DateTime.DaysInMonth(year, month)) { day++; } else { day = 1; if (month < 12) { month++; } else { month = 1; year++; } } var jsonObj = JSONObject.Create(); jsonObj.AddField("year", year); jsonObj.AddField("month", month); jsonObj.AddField("day", day); GameSaveData.SetNextDailyEntranceDate(jsonObj.Print()); } } if (DailyEntrance) { GameSaveData.IncreaseDailyEntranceNumber(); } InformDailyEntrance = DailyEntrance && GameSaveData.GetDailyEntranceNumber() > 0; }