MainAccountData.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LitJson;
  5. using System;
  6. using MetaClient;
  7. public class MainAccountData
  8. {
  9. public static MainAccountData Instance = null;
  10. public static string ver = "1.0.1";
  11. public static string code = "";
  12. public static string NickName = "";
  13. public static string Avatar = "";
  14. public static string Gender = null;
  15. public static string Country = "中国";
  16. public static string Province = "";
  17. public static string City = "";
  18. public static string Device = "";
  19. public static string ShareId = "";
  20. public static string Scene = "";
  21. public MainAccountData(JsonData _data)
  22. {
  23. Instance = this;
  24. this.servertime = float.Parse(_data["t"].ToString());
  25. this.curtime = Time.realtimeSinceStartup;
  26. this.table_version = _data["table_version"].ToString();
  27. this.token = _data["token"].ToString();
  28. this.app_setting = _data["app_setting"];
  29. this.cdn_url = this.app_setting["cdn_url"].ToString();
  30. this.user = _data["user"];
  31. this.user_base = _data["user_base"];
  32. //this.user_sign = _data["user_sign"];
  33. //this.user_lottery = _data["user_lottery"];
  34. //this.userId = this.user["user_id"].ToString();
  35. //this.openid = this.user_base["openid"].ToString();
  36. //Debug.Log("user_id:" + userId);
  37. //Debug.Log("ver:" + ver);
  38. this.day_first = _data["day_first"].ToString() == "1";
  39. //this.is_new = ((IDictionary)_data).Contains("is_new") ? true : false;
  40. }
  41. public string cdn_url;
  42. public bool day_first;
  43. public string token;
  44. public JsonData app_setting;
  45. public string table_version;
  46. //public bool is_new;
  47. public JsonData user;
  48. public JsonData user_base;
  49. //public JsonData user_sign;
  50. //public JsonData user_lottery;
  51. //public JsonData user_share;
  52. //public JsonData user_video;
  53. //public JsonData user_client;
  54. //public JsonData user_deny;
  55. //public string message;
  56. //public string userId;
  57. //public string openid;
  58. public float servertime;
  59. public float curtime;
  60. public float ServerTime
  61. {
  62. get
  63. {
  64. var time = Time.realtimeSinceStartup;
  65. return this.servertime + Mathf.Ceil((time - this.curtime) * 0.001f);
  66. }
  67. }
  68. public static void OnUpdateAccount(string _data)
  69. {
  70. }
  71. public void OnGetAccountConfig(JsonData _config)
  72. {
  73. }
  74. public void JundgCfg(string ver, Action configokcallback)
  75. {
  76. WebManager.GetInstance.HttpPostRequest_Send(PROTOCOLS.Config, null, (jsonData) =>
  77. {
  78. DataController.SetCfg(jsonData["configs"]);
  79. if (configokcallback != null) configokcallback();
  80. }, (value) =>
  81. {
  82. Debug.Log("未加载到配置表");
  83. });
  84. }
  85. public void CheckConfig(System.Action getconfigcb)
  86. {
  87. //mgetconfigcb = getconfigcb;
  88. //var curconfig = PlayerPrefs.GetString("accountconfigkey");
  89. //var curconfigver = PlayerPrefs.GetString("accountconfigver", "");
  90. //curconfig = test ? null : curconfig;
  91. //if (curconfig != "")
  92. //{
  93. // if (curconfigver == this.table_version && !test)
  94. // {
  95. // Debug.Log("sever配置是最新的..." + this.table_version);
  96. // this.configs = curconfig;
  97. // this.OnGetAccountConfig(this.configs);
  98. // if (getconfigcb != null) getconfigcb();
  99. // }
  100. // else
  101. // {
  102. // Dictionary<string, string> agsdic = new Dictionary<string, string>();
  103. // agsdic.Add("version", table_version);
  104. // agsdic.Add("v", table_version);
  105. // WebManager.GetInstance.HttpPostRequest_Send(PROTOCOLS.Config, agsdic, this.CheckLocalConfig_completecb, this.CheckLocalConfig_errorcb);
  106. // }
  107. //}
  108. //else
  109. //{
  110. // Dictionary<string, string> agsdic = new Dictionary<string, string>();
  111. // agsdic.Add("version", table_version);
  112. // agsdic.Add("v", table_version);
  113. // WebManager.GetInstance.HttpPostRequest_Send(PROTOCOLS.Config, agsdic, this.CheckLocalConfig_completecb, this.CheckLocalConfig_errorcb);
  114. //}
  115. }
  116. private void CheckLocalConfig_completecb(object _objtext)
  117. {
  118. //string _text = _objtext as string;
  119. //JsonData hashtable = JsonMapper.ToObject(_text);
  120. //JsonData _config = hashtable["configs"];
  121. //this.OnGetAccountConfig(_config);
  122. //PlayerPrefs.SetString("accountconfigkey", _text);
  123. //PlayerPrefs.SetString("accountconfigver", table_version);
  124. //if (mgetconfigcb != null) mgetconfigcb();
  125. }
  126. private void CheckLocalConfig_errorcb(object _objtext)
  127. {
  128. //Debug.Log("未加载到配置表");
  129. }
  130. public static string LocalCode
  131. {
  132. get
  133. {
  134. var code = GameEntry.Setting.GetString("localcode");
  135. if (code == "")
  136. {
  137. System.DateTime _time = System.DateTime.Now;
  138. System.DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
  139. var _rimeStr = (long)(_time - startTime).TotalSeconds;
  140. var _rang = UnityEngine.Random.Range(10000, 99999);
  141. code = "xj_" + _rimeStr + _rang;
  142. GameEntry.Setting.SetString("localcode", code);
  143. Debug.Log("新用户" + code);
  144. }
  145. else
  146. {
  147. Debug.Log("老用户" + code);
  148. }
  149. return code;
  150. }
  151. }
  152. }