Initializer.cs 9.3 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 = "31-2";
  106. gameObject.AddScript<RobotManager>();
  107. progress = "32";
  108. StartCoroutine(IInitialize());
  109. }
  110. catch (Exception e)
  111. {
  112. GameObject.Find("Canvas").GetChild(0).SetActive(true);
  113. GameObject.Find("Canvas").GetChild(1).SetActive(true);
  114. GameObject.Find("Text").GetComponent<Text>().text = progress + "\n" + e;
  115. throw new Exception();
  116. }
  117. }
  118. private void InitializeDataEye()
  119. {
  120. if (Application.platform == RuntimePlatform.IPhonePlayer)
  121. {
  122. DataEyeGA.Init("C5790DBD2CFE97BD18C7BE9A95482C05", DataEyeGA.PlatformType.IOS, "Official", "IOS");
  123. }
  124. else if (Application.isMobilePlatform)
  125. {
  126. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.ADR, "Official", "Android");
  127. }
  128. else if (Application.isEditor)
  129. {
  130. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.WP, "Official", "Windows");
  131. }
  132. }
  133. public static void InitializeEntrance()
  134. {
  135. if (Instance.CatchException)
  136. {
  137. ManaDebug.TryCatch(Initialize, EnableDebugLab);
  138. }
  139. else
  140. {
  141. Initialize();
  142. }
  143. }
  144. public static Text DebugLab;
  145. public static void Initialize()
  146. {
  147. DebugLab = GameObject.Find("U_DebugLab").GetComponent<Text>();
  148. DebugLab.text = "Error code : 1";
  149. ManaTutorial.TutorialA = ManaData.GetPlayerBool("TutorialA");
  150. DebugLab.text = "Error code : 1-1";
  151. ManaTutorial.TutorialB_ = ManaData.GetPlayerBool("TutorialB");
  152. DebugLab.text = "Error code : 1-2";
  153. ManaTutorial.TutorialC_ = ManaData.GetPlayerBool("TutorialC");
  154. DebugLab.text = "Error code : 1-3";
  155. ManaTutorial.TutorialD_ = ManaData.GetPlayerBool("TutorialD");
  156. DebugLab.text = "Error code : 1-4";
  157. ManaTutorial.TutorialE_ = ManaData.GetPlayerBool("TutorialE");
  158. DebugLab.text = "Error code : 1-5";
  159. ManaTutorial.TutorialPlazaRoom_ = ManaData.GetPlayerBool("TutorialPlazaRoom");
  160. DebugLab.text = "Error code : 1-5-1";
  161. ManaTutorial.TutorialIndexA = ManaData.GetPlayerInt("TutorialIndexA");
  162. DebugLab.text = "Error code : 1-6";
  163. ManaTutorial.TutorialIndexB = ManaData.GetPlayerInt("TutorialIndexB");
  164. DebugLab.text = "Error code : 1-7";
  165. ManaTutorial.TutorialIndexC = ManaData.GetPlayerInt("TutorialIndexC");
  166. DebugLab.text = "Error code : 1-8";
  167. ManaTutorial.TutorialIndexD = ManaData.GetPlayerInt("TutorialIndexD");
  168. DebugLab.text = "Error code : 1-9";
  169. ManaTutorial.TutorialIndexE = ManaData.GetPlayerInt("TutorialIndexE");
  170. DebugLab.text = "Error code : 1-10";
  171. ManaTutorial.TutorialIndexPlazaRoom = ManaData.GetPlayerInt("TutorialIndexPlazaRoom");
  172. DebugLab.text = "Error code : 1-10-1";
  173. Bundle.LoadAtlasSprites();
  174. DebugLab.text = "Error code : 1-11";
  175. for (int i = 0; i < RegistList.Count; i++)
  176. {
  177. DebugLab.text = "Error code : 1-12-" + i;
  178. //Debug.Log(i + " " + RegistList[i].GetType());
  179. RegistList[i].Instantiate();
  180. }
  181. DebugLab.text = "Error code : 2";
  182. for (int i = 0; i < RegistList.Count; i++)
  183. {
  184. DebugLab.text = "Error code : 2-" + i;
  185. RegistList[i].RegistReference();
  186. }
  187. DebugLab.text = "Error code : 3";
  188. for (int i = 0; i < RegistList.Count; i++)
  189. {
  190. DebugLab.text = "Error code : 3-" + i;
  191. RegistList[i].RegistValueA();
  192. }
  193. DebugLab.text = "Error code : 4";
  194. for (int i = 0; i < RegistList.Count; i++)
  195. {
  196. DebugLab.text = "Error code : 4-" + i;
  197. RegistList[i].RegistValueB();
  198. }
  199. DebugLab.text = "Error code : 5";
  200. for (int i = 0; i < RegistList.Count; i++)
  201. {
  202. DebugLab.text = "Error code : 5-" + i;
  203. RegistList[i].RegistValueC();
  204. RegistList[i].enabled = true;
  205. }
  206. DebugLab.text = "Error code : 6";
  207. Complete = true;
  208. if (ManaServer.NotificationReady)
  209. {
  210. ManaReso.Get("C_Notify").TweenForCG();
  211. }
  212. DebugLab.text = "Error code : 7";
  213. ManaPlayer.InitializeDressRoom();
  214. DebugLab.text = "Error code : 8";
  215. ManaCenter.LoginCallbackInitial(new JsonData());
  216. //debugLab.text = "Error code : 9";
  217. //SFSManager.GardenSmartFox.Connector.Connect();
  218. DebugLab.text = "Error code : 10";
  219. StringFilter.Init();
  220. DebugLab.text = "Error code : 11";
  221. ManaIAP.Initialize();
  222. DebugLab.text = "Error code : 12";
  223. ManaVisit.Initialize();
  224. DebugLab.text = "Error code : 13";
  225. ManaSocial.InitializeRankPanel();
  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. }