Initializer.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. public class Initializer : MonoBehaviour
  10. {
  11. #region 变量
  12. public bool DebugMode;
  13. public bool CatchException;
  14. public GameObject DebugModeGo;
  15. public static bool Complete;
  16. public static Initializer Instance;
  17. public static Transform Transform;
  18. public static List<Regist> RegistList = new List<Regist>();
  19. #endregion
  20. private void Awake()
  21. {
  22. try
  23. {
  24. InitializeDataEye();
  25. }
  26. catch (Exception)
  27. {
  28. }
  29. string progress = "";
  30. try
  31. {
  32. progress = "1";
  33. Application.targetFrameRate = 50;
  34. progress = "2";
  35. DontDestroyOnLoad(gameObject);
  36. progress = "3";
  37. ManaServer.Login(ManaCenter.LoginCallbackInitial);
  38. progress = "4";
  39. ManaServer.MailRequest();
  40. progress = "5";
  41. ManaServer.RankRequest();
  42. progress = "6";
  43. ManaServer.IOSAlipayRequest();
  44. progress = "7";
  45. ManaServer.NotificationRequest();
  46. Instance = this;
  47. Transform = transform;
  48. progress = "8";
  49. if (DebugMode)
  50. {
  51. Instantiate(DebugModeGo, transform);
  52. }
  53. else
  54. {
  55. gameObject.AddComponent<Bundle>();
  56. }
  57. progress = "9";
  58. gameObject.AddComponent<ManaIAP>();
  59. progress = "10";
  60. gameObject.AddComponent<ManaVisit>();
  61. progress = "11";
  62. gameObject.AddComponent<ManaDebug>();
  63. progress = "12";
  64. gameObject.AddScript<Auxiliary>();
  65. progress = "13";
  66. gameObject.AddScript<ManaData>();
  67. progress = "14";
  68. gameObject.AddScript<ManaReso>();
  69. progress = "15";
  70. gameObject.AddScript<ManaTutorial>();
  71. progress = "16";
  72. gameObject.AddScript<ManaLan>();
  73. progress = "17";
  74. gameObject.AddScript<ManaAnim>();
  75. progress = "18";
  76. gameObject.AddScript<ManaAudio>();
  77. progress = "19";
  78. gameObject.AddScript<ManaAchieve>();
  79. progress = "20";
  80. gameObject.AddScript<ManaUI>();
  81. progress = "21";
  82. gameObject.AddScript<ManaSign>();
  83. progress = "22";
  84. gameObject.AddScript<ManaCenter>();
  85. progress = "23";
  86. gameObject.AddScript<ManaGarden>();
  87. progress = "24";
  88. gameObject.AddScript<ManaPlayer>();
  89. progress = "25";
  90. gameObject.AddScript<ManaServer>();
  91. progress = "26";
  92. gameObject.AddScript<ManaMiniGame>();
  93. progress = "27";
  94. gameObject.AddScript<ManaInfoBox>();
  95. progress = "28";
  96. gameObject.AddScript<ManaSocial>();
  97. progress = "29";
  98. gameObject.AddScript<ManaNickName>();
  99. progress = "30";
  100. gameObject.AddScript<SFSManager>();
  101. progress = "31";
  102. gameObject.AddScript<PlazaRoomMge>();
  103. progress = "31-1";
  104. gameObject.AddScript<ChestMge>();
  105. progress = "32";
  106. StartCoroutine(IInitialize());
  107. }
  108. catch (Exception e)
  109. {
  110. GameObject.Find("Canvas").GetChild(0).SetActive(true);
  111. GameObject.Find("Canvas").GetChild(1).SetActive(true);
  112. GameObject.Find("Text").GetComponent<Text>().text = progress + "\n" + e;
  113. throw new Exception();
  114. }
  115. }
  116. private void InitializeDataEye()
  117. {
  118. if (Application.platform == RuntimePlatform.IPhonePlayer)
  119. {
  120. DataEyeGA.Init("C5790DBD2CFE97BD18C7BE9A95482C05", DataEyeGA.PlatformType.IOS, "Official", "IOS");
  121. }
  122. else if (Application.isMobilePlatform)
  123. {
  124. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.ADR, "Official", "Android");
  125. }
  126. else if (Application.isEditor)
  127. {
  128. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.WP, "Official", "Windows");
  129. }
  130. }
  131. public static void InitializeEntrance()
  132. {
  133. if (Instance.CatchException)
  134. {
  135. ManaDebug.TryCatch(Initialize, EnableDebugLab);
  136. }
  137. else
  138. {
  139. Initialize();
  140. }
  141. }
  142. public static Text DebugLab;
  143. public static void Initialize()
  144. {
  145. DebugLab = GameObject.Find("U_DebugLab").GetComponent<Text>();
  146. DebugLab.text = "Error code : 1";
  147. ManaTutorial.TutorialA = ManaData.GetPlayerBool("TutorialA");
  148. DebugLab.text = "Error code : 1-1";
  149. ManaTutorial.TutorialB_ = ManaData.GetPlayerBool("TutorialB");
  150. DebugLab.text = "Error code : 1-2";
  151. ManaTutorial.TutorialC_ = ManaData.GetPlayerBool("TutorialC");
  152. DebugLab.text = "Error code : 1-3";
  153. ManaTutorial.TutorialD_ = ManaData.GetPlayerBool("TutorialD");
  154. DebugLab.text = "Error code : 1-4";
  155. ManaTutorial.TutorialE_ = ManaData.GetPlayerBool("TutorialE");
  156. DebugLab.text = "Error code : 1-5";
  157. ManaTutorial.TutorialPlazaRoom_ = ManaData.GetPlayerBool("TutorialPlazaRoom");
  158. DebugLab.text = "Error code : 1-5-1";
  159. ManaTutorial.TutorialIndexA = ManaData.GetPlayerInt("TutorialIndexA");
  160. DebugLab.text = "Error code : 1-6";
  161. ManaTutorial.TutorialIndexB = ManaData.GetPlayerInt("TutorialIndexB");
  162. DebugLab.text = "Error code : 1-7";
  163. ManaTutorial.TutorialIndexC = ManaData.GetPlayerInt("TutorialIndexC");
  164. DebugLab.text = "Error code : 1-8";
  165. ManaTutorial.TutorialIndexD = ManaData.GetPlayerInt("TutorialIndexD");
  166. DebugLab.text = "Error code : 1-9";
  167. ManaTutorial.TutorialIndexE = ManaData.GetPlayerInt("TutorialIndexE");
  168. DebugLab.text = "Error code : 1-10";
  169. ManaTutorial.TutorialIndexPlazaRoom = ManaData.GetPlayerInt("TutorialIndexPlazaRoom");
  170. DebugLab.text = "Error code : 1-10-1";
  171. Bundle.LoadAtlasSprites();
  172. DebugLab.text = "Error code : 1-11";
  173. for (int i = 0; i < RegistList.Count; i++)
  174. {
  175. DebugLab.text = "Error code : 1-12-" + i;
  176. //Debug.Log(i + " " + RegistList[i].GetType());
  177. RegistList[i].Instantiate();
  178. }
  179. DebugLab.text = "Error code : 2";
  180. for (int i = 0; i < RegistList.Count; i++)
  181. {
  182. DebugLab.text = "Error code : 2-" + i;
  183. RegistList[i].RegistReference();
  184. }
  185. DebugLab.text = "Error code : 3";
  186. for (int i = 0; i < RegistList.Count; i++)
  187. {
  188. DebugLab.text = "Error code : 3-" + i;
  189. RegistList[i].RegistValueA();
  190. }
  191. DebugLab.text = "Error code : 4";
  192. for (int i = 0; i < RegistList.Count; i++)
  193. {
  194. DebugLab.text = "Error code : 4-" + i;
  195. RegistList[i].RegistValueB();
  196. }
  197. DebugLab.text = "Error code : 5";
  198. for (int i = 0; i < RegistList.Count; i++)
  199. {
  200. DebugLab.text = "Error code : 5-" + i;
  201. RegistList[i].RegistValueC();
  202. RegistList[i].enabled = true;
  203. }
  204. DebugLab.text = "Error code : 6";
  205. Complete = true;
  206. if (ManaServer.NotificationReady)
  207. {
  208. ManaReso.Get("C_Notify").TweenForCG();
  209. }
  210. DebugLab.text = "Error code : 7";
  211. ManaPlayer.InitializeDressRoom();
  212. DebugLab.text = "Error code : 8";
  213. ManaCenter.LoginCallbackInitial(new JsonData());
  214. //debugLab.text = "Error code : 9";
  215. //SFSManager.GardenSmartFox.Connector.Connect();
  216. DebugLab.text = "Error code : 10";
  217. StringFilter.Init();
  218. DebugLab.text = "Error code : 11";
  219. ManaIAP.Initialize();
  220. DebugLab.text = "Error code : 12";
  221. ManaVisit.Initialize();
  222. DebugLab.text = "Error code : 13";
  223. ManaSocial.InitializeRankPanel();
  224. DebugLab.text = "Error code : 14";
  225. ManaReso.Release();
  226. if (Instance.DebugMode)
  227. {
  228. ActivateGame();
  229. }
  230. else
  231. {
  232. ShowLoadingPanel();
  233. }
  234. }
  235. private static void ShowLoadingPanel()
  236. {
  237. ManaReso.Get("U_Group").TweenForCG();
  238. ManaReso.Get<CanvasGroup>("C_Main").alpha = 0;
  239. Auxiliary.Instance.DelayCall(ActivateGame, 3f);
  240. }
  241. private static void ActivateGame()
  242. {
  243. ManaReso.Get("U_LoadingPanel").TweenForCG();
  244. ManaReso.Get<CanvasGroup>("C_Main").alpha = 1;
  245. ManaAudio.MusicTheme.TweenForAudio();
  246. }
  247. public static void EnableDebugLab()
  248. {
  249. ManaReso.Get<CanvasGroup>("U_Group").alpha = 0;
  250. ManaReso.Get<Text>("U_DebugLab").enabled = true;
  251. throw new Exception();
  252. }
  253. public IEnumerator IInitialize()
  254. {
  255. while (!Logo.Complete)
  256. {
  257. yield return null;
  258. }
  259. while (!Bundle.Complete)
  260. {
  261. yield return null;
  262. }
  263. while (ManaData.DamageLock)
  264. {
  265. yield return null;
  266. }
  267. InitializeEntrance();
  268. }
  269. }