Initializer.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. using System.Linq.Expressions;
  10. public class LogoSceneLabel
  11. {
  12. public static string DebugText = "DebugText";
  13. public static string ManagerGame = "ManagerGame";
  14. }
  15. public class Initializer : MonoBehaviour
  16. {
  17. #region Config
  18. public bool AuditEdition;
  19. public bool DebugMode;
  20. public bool CatchException;
  21. public GameObject DebugModeGo;
  22. public static bool Inited;
  23. public static string InitScriptProgress;
  24. public static Text DebugText;
  25. public static Initializer Instance;
  26. public static List<Regist> RegistList = new List<Regist>();
  27. #endregion
  28. private void Awake()
  29. {
  30. if (CatchException)
  31. {
  32. try
  33. {
  34. InitDataEye();
  35. }
  36. catch (Exception)
  37. {
  38. }
  39. }
  40. else
  41. {
  42. InitDataEye();
  43. }
  44. if (CatchException)
  45. {
  46. try
  47. {
  48. InitScript();
  49. }
  50. catch (Exception e)
  51. {
  52. Text debugText = GameObject.Find(LogoSceneLabel.DebugText).GetComponent<Text>();
  53. debugText.SetAlpha(1);
  54. debugText.text = InitScriptProgress + "\n" + e;
  55. throw new Exception();
  56. }
  57. }
  58. else
  59. {
  60. InitScript();
  61. }
  62. }
  63. private void InitDataEye()
  64. {
  65. if (Application.platform == RuntimePlatform.IPhonePlayer)
  66. {
  67. DataEyeGA.Init("C5790DBD2CFE97BD18C7BE9A95482C05", DataEyeGA.PlatformType.IOS, "Official", "IOS");
  68. }
  69. else if (Application.isMobilePlatform)
  70. {
  71. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.ADR, "Official", "Android");
  72. }
  73. else if (Application.isEditor)
  74. {
  75. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.WP, "Official", "Windows");
  76. }
  77. }
  78. private void InitScript()
  79. {
  80. int index = 1;
  81. InitScriptProgress = index++.ToString();
  82. Application.targetFrameRate = 50;
  83. InitScriptProgress = index++.ToString();
  84. DontDestroyOnLoad(gameObject);
  85. InitScriptProgress = index++.ToString();
  86. HttpManager.Login(Manager.FirstTimeLoginCallback);
  87. InitScriptProgress = index++.ToString();
  88. HttpManager.GetMailAwardData();
  89. InitScriptProgress = index++.ToString();
  90. HttpManager.GetRankData();
  91. InitScriptProgress = index++.ToString();
  92. HttpManager.GetAlipayFlag();
  93. InitScriptProgress = index++.ToString();
  94. HttpManager.GetAnnounceData();
  95. Instance = this;
  96. InitScriptProgress = index++.ToString();
  97. if (DebugMode)
  98. {
  99. Instantiate(DebugModeGo, transform);
  100. }
  101. else
  102. {
  103. gameObject.AddComponent<Bundle>();
  104. }
  105. InitScriptProgress = index++.ToString();
  106. gameObject.AddComponent<IAPManager>();
  107. InitScriptProgress = index++.ToString();
  108. gameObject.AddComponent<VisitManager>();
  109. InitScriptProgress = index++.ToString();
  110. gameObject.AddComponent<DebugManager>();
  111. InitScriptProgress = index++.ToString();
  112. gameObject.AddScript<Auxiliary>();
  113. InitScriptProgress = index++.ToString();
  114. gameObject.AddScript<ConfigManager>();
  115. InitScriptProgress = index++.ToString();
  116. gameObject.AddScript<ResourceManager>();
  117. InitScriptProgress = index++.ToString();
  118. gameObject.AddScript<TutorialManager>();
  119. InitScriptProgress = index++.ToString();
  120. gameObject.AddScript<LanguageManager>();
  121. InitScriptProgress = index++.ToString();
  122. gameObject.AddScript<AnimManager>();
  123. InitScriptProgress = index++.ToString();
  124. gameObject.AddScript<AudioManager>();
  125. InitScriptProgress = index++.ToString();
  126. gameObject.AddScript<AchieveManager>();
  127. InitScriptProgress = index++.ToString();
  128. gameObject.AddScript<UIManager>();
  129. InitScriptProgress = index++.ToString();
  130. gameObject.AddScript<SignManager>();
  131. InitScriptProgress = index++.ToString();
  132. gameObject.AddScript<Manager>();
  133. InitScriptProgress = index++.ToString();
  134. gameObject.AddScript<GardenManager>();
  135. InitScriptProgress = index++.ToString();
  136. gameObject.AddScript<PlayerManager>();
  137. InitScriptProgress = index++.ToString();
  138. gameObject.AddScript<HttpManager>();
  139. InitScriptProgress = index++.ToString();
  140. gameObject.AddScript<MiniGameManager>();
  141. InitScriptProgress = index++.ToString();
  142. gameObject.AddScript<InfoBoxManager>();
  143. InitScriptProgress = index++.ToString();
  144. gameObject.AddScript<SocialManager>();
  145. InitScriptProgress = index++.ToString();
  146. gameObject.AddScript<NickNameManager>();
  147. InitScriptProgress = index++.ToString();
  148. gameObject.AddScript<SFSManager>();
  149. InitScriptProgress = index++.ToString();
  150. gameObject.AddScript<PlazaRoomManager>();
  151. InitScriptProgress = index++.ToString();
  152. gameObject.AddScript<ChestManager>();
  153. InitScriptProgress = index++.ToString();
  154. gameObject.AddScript<RobotManager>();
  155. InitScriptProgress = index++.ToString();
  156. gameObject.AddScript<CDMinigamePanelManager>();
  157. InitScriptProgress = index++.ToString();
  158. gameObject.AddScript<EnterMinigamePanelManager>();
  159. InitScriptProgress = index++.ToString();
  160. gameObject.AddScript<PlazaroomMemberPanel>();
  161. InitScriptProgress = index++.ToString();
  162. gameObject.AddScript<FriendPanel>();
  163. InitScriptProgress = index++.ToString();
  164. gameObject.AddScript<AddFriendPanel>();
  165. InitScriptProgress = index++.ToString();
  166. gameObject.AddScript<MessagePanel>();
  167. InitScriptProgress = index++.ToString();
  168. gameObject.AddScript<FashionShowEditPage>();
  169. InitScriptProgress = index++.ToString();
  170. StartCoroutine(WaitToInit());
  171. }
  172. public static void InitEntrance()
  173. {
  174. if (Instance.CatchException)
  175. {
  176. DebugManager.TryCatch(Init, EnableDebugLab);
  177. }
  178. else
  179. {
  180. Init();
  181. }
  182. }
  183. public static void Init()
  184. {
  185. DebugText = GameObject.Find(CanvasLabel.U_DebugLab).GetComponent<Text>();
  186. DebugText.text = "Error code : 1";
  187. TutorialManager.NewplayerTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.NewplayerTutorial);
  188. DebugText.text = "Error code : 1-1";
  189. TutorialManager.memoryMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.MemoryMinigameTutorial);
  190. DebugText.text = "Error code : 1-2";
  191. TutorialManager.visitTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.VisitTutorial);
  192. DebugText.text = "Error code : 1-3";
  193. TutorialManager.dressroomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.DressroomTutorial);
  194. DebugText.text = "Error code : 1-4";
  195. TutorialManager.findMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindMinigameTutorial);
  196. DebugText.text = "Error code : 1-5";
  197. TutorialManager.plazaRoomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.TutorialPlazaRoom);
  198. DebugText.text = "Error code : 1-5-1";
  199. TutorialManager.NewplayerTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.NewplayerTutorialIndex);
  200. DebugText.text = "Error code : 1-6";
  201. TutorialManager.MemoryMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.MemoryMinigameTutorialIndex);
  202. DebugText.text = "Error code : 1-7";
  203. TutorialManager.VisitTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.VisitTutorialIndex);
  204. DebugText.text = "Error code : 1-8";
  205. TutorialManager.DressroomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.DressroomIndex);
  206. DebugText.text = "Error code : 1-9";
  207. TutorialManager.FindMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindMinigameTutorialIndex);
  208. DebugText.text = "Error code : 1-10";
  209. TutorialManager.PlazaRoomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.TutorialIndexPlazaRoom);
  210. DebugText.text = "Error code : 1-10-1";
  211. Bundle.LoadAtlasSprites();
  212. DebugText.text = "Error code : 1-11";
  213. for (int i = 0; i < RegistList.Count; i++)
  214. {
  215. DebugText.text = "Error code : 1-12-" + i;
  216. //Debug.Log(i + " " + RegistList[i].GetType());
  217. RegistList[i].InstantiatePrefabs();
  218. }
  219. DebugText.text = "Error code : 2";
  220. for (int i = 0; i < RegistList.Count; i++)
  221. {
  222. DebugText.text = "Error code : 2-" + i;
  223. RegistList[i].RegistReference();
  224. }
  225. DebugText.text = "Error code : 3";
  226. for (int i = 0; i < RegistList.Count; i++)
  227. {
  228. DebugText.text = "Error code : 3-" + i;
  229. RegistList[i].FirstInit();
  230. }
  231. DebugText.text = "Error code : 4";
  232. for (int i = 0; i < RegistList.Count; i++)
  233. {
  234. DebugText.text = "Error code : 4-" + i;
  235. RegistList[i].SecondInit();
  236. }
  237. DebugText.text = "Error code : 5";
  238. for (int i = 0; i < RegistList.Count; i++)
  239. {
  240. DebugText.text = "Error code : 5-" + i;
  241. RegistList[i].ThirdInit();
  242. RegistList[i].enabled = true;
  243. }
  244. DebugText.text = "Error code : 6";
  245. Inited = true;
  246. if (HttpManager.IsAnnounceReady)
  247. {
  248. ResourceManager.SetActive(CanvasLabel.C_NotifyParent, true);
  249. ResourceManager.Get(CanvasLabel.C_Notify).TweenForCG();
  250. }
  251. DebugText.text = "Error code : 7";
  252. PlayerManager.InitDressRoom();
  253. DebugText.text = "Error code : 8";
  254. Manager.FirstTimeLoginCallback(new JsonData());
  255. //debugLab.text = "Error code : 9";
  256. //SFSManager.GardenSmartFox.Connector.Connect();
  257. DebugText.text = "Error code : 10";
  258. StringFilter.Init();
  259. DebugText.text = "Error code : 11";
  260. IAPManager.Init();
  261. DebugText.text = "Error code : 12";
  262. VisitManager.Init();
  263. DebugText.text = "Error code : 13";
  264. SocialManager.InitRankPanel();
  265. if (Instance.DebugMode)
  266. {
  267. ActivateGame();
  268. }
  269. else
  270. {
  271. ShowLoadingPanel();
  272. }
  273. }
  274. public IEnumerator WaitToInit()
  275. {
  276. while (!Logo.Complete)
  277. {
  278. yield return null;
  279. }
  280. while (!Bundle.Complete)
  281. {
  282. yield return null;
  283. }
  284. while (ConfigManager.PlayerDocumentDamageFlag)
  285. {
  286. yield return null;
  287. }
  288. InitEntrance();
  289. }
  290. private static float LoadingDelayTime = 3f;
  291. private static void ShowLoadingPanel()
  292. {
  293. ResourceManager.Get(CanvasLabel.U_Group).TweenForCG();
  294. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 0;
  295. ResourceManager.SetText(CanvasLabel.U_Lab, Language.GetStr(LanguageLabel.UI__U_Lab));
  296. Auxiliary.Instance.DelayCall(ActivateGame, LoadingDelayTime);
  297. }
  298. public static void SetWarningTitleAndText()
  299. {
  300. SystemLanguage language = Application.systemLanguage;
  301. if (Instance.AuditEdition)
  302. {
  303. language = SystemLanguage.ChineseSimplified;
  304. }
  305. ResourceManager.SetText(CanvasLabel.U_WarningTitle, Language.GetStr(LanguageLabel.UI__U_WarningTitle, language));
  306. if (language == SystemLanguage.ChineseSimplified)
  307. {
  308. ResourceManager.SetText(CanvasLabel.U_WarningText, Language.GetStr(LanguageLabel.UI__U_WarningText, language));
  309. }
  310. else if (language == SystemLanguage.ChineseTraditional)
  311. {
  312. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  313. }
  314. else
  315. {
  316. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  317. }
  318. }
  319. private static void ActivateGame()
  320. {
  321. ResourceManager.Get(CanvasLabel.U_LoadingPanel).TweenForCG();
  322. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 1;
  323. AudioManager.GardenThemeAudio.TweenForAudio();
  324. }
  325. public static void EnableDebugLab()
  326. {
  327. ResourceManager.Get<CanvasGroup>(CanvasLabel.U_Group).alpha = 0;
  328. ResourceManager.Get<Text>(CanvasLabel.U_DebugLab).enabled = true;
  329. }
  330. }