Initializer.cs 15 KB

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