public static IEnumerator GetServerTime() { string url = "https://api.backmobi.pro/session/timestamp"; UnityWebRequest www = UnityWebRequest.Get(url); yield return(www.SendWebRequest()); if (!www.isNetworkError) { string time = www.downloadHandler.text; time = time.Remove(0, ('"' + "{timestamp" + '"' + ':').Length); time = time.Remove(time.Length - 1); DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(double.Parse(time, System.Globalization.CultureInfo.InvariantCulture.NumberFormat)); UrmobiServerDT = dtDateTime; LocalUrmobiServerDT = UrmobiServerDT.ToLocalTime(); EventManager.Notify(null, new GameEventArgs(Events.DateTime.URMOBI_DATE_GOTTEN)); ServerTimeInited = true; Debug.LogError($"Server Time: {dtDateTime}"); Debug.LogError($"Local Time: {dtDateTime.ToLocalTime()}"); } else { Debug.LogError($"ERROR {www.error}"); } }
private void Tick() { UrmobiServerDT = UrmobiServerDT.AddSeconds(Time.unscaledDeltaTime); LocalUrmobiServerDT = LocalUrmobiServerDT.AddSeconds(Time.unscaledDeltaTime); tickEvent?.Invoke(); }