Initializer.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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.fashionShowTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FashionShowTutorial);
  208. DebugText.text = "Error code : 1-4-1";
  209. TutorialManager.findSoloMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindSoloMinigameTutorial);
  210. DebugText.text = "Error code : 1-5";
  211. TutorialManager.findMissingMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindMissingMinigameTutorial);
  212. DebugText.text = "Error code : 1-5-0";
  213. TutorialManager.plazaRoomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.TutorialPlazaRoom);
  214. DebugText.text = "Error code : 1-5-1";
  215. TutorialManager.NewplayerTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.NewplayerTutorialIndex);
  216. DebugText.text = "Error code : 1-6";
  217. TutorialManager.MemoryMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.MemoryMinigameTutorialIndex);
  218. DebugText.text = "Error code : 1-7";
  219. TutorialManager.VisitTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.VisitTutorialIndex);
  220. DebugText.text = "Error code : 1-8";
  221. TutorialManager.DressroomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.DressroomIndex);
  222. DebugText.text = "Error code : 1-9";
  223. TutorialManager.FindSoloMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindSoloMinigameTutorialIndex);
  224. DebugText.text = "Error code : 1-10";
  225. TutorialManager.FindMissingMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindMissingMinigameTutorialIndex);
  226. DebugText.text = "Error code : 1-10-0";
  227. TutorialManager.PlazaRoomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.TutorialIndexPlazaRoom);
  228. DebugText.text = "Error code : 1-10-1";
  229. TutorialManager.FashionShowTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FashionShowTutorialIndex);
  230. DebugText.text = "Error code : 1-10-1";
  231. Bundle.LoadAtlasSprites();
  232. DebugText.text = "Error code : 7";
  233. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  234. attributeList.RemoveAt(0);
  235. //attributeList.AddRange(Bundle.NewDressroomConfigs);
  236. PlayerManager.CreateCloseItems(attributeList);
  237. DebugText.text = "Error code : 1-11";
  238. //Bundle.LoadAllDressBundleAssetsIntoDragonbone();
  239. DebugText.text = "Error code : 1-11-1";
  240. for (int i = 0; i < RegistList.Count; i++)
  241. {
  242. DebugText.text = "Error code : 1-12-" + i;
  243. //Debug.Log(i + " " + RegistList[i].GetType());
  244. RegistList[i].InstantiatePrefabs();
  245. }
  246. DebugText.text = "Error code : 2";
  247. }
  248. public static void InitGame()
  249. {
  250. InstantiatePrefabs();
  251. for (int i = 0; i < RegistList.Count; i++)
  252. {
  253. DebugText.text = "Error code : 2-" + i;
  254. RegistList[i].RegistReference();
  255. }
  256. DebugText.text = "Error code : 3";
  257. for (int i = 0; i < RegistList.Count; i++)
  258. {
  259. DebugText.text = "Error code : 3-" + i;
  260. RegistList[i].FirstInit();
  261. }
  262. DebugText.text = "Error code : 4";
  263. for (int i = 0; i < RegistList.Count; i++)
  264. {
  265. DebugText.text = "Error code : 4-" + i;
  266. RegistList[i].SecondInit();
  267. }
  268. DebugText.text = "Error code : 5";
  269. for (int i = 0; i < RegistList.Count; i++)
  270. {
  271. DebugText.text = "Error code : 5-" + i;
  272. RegistList[i].ThirdInit();
  273. RegistList[i].enabled = true;
  274. }
  275. DebugText.text = "Error code : 6";
  276. Inited = true;
  277. if (HttpManager.IsAnnounceReady)
  278. {
  279. ResourceManager.SetActive(CanvasLabel.C_NotifyParent, true);
  280. ResourceManager.Get(CanvasLabel.C_Notify).TweenForCG();
  281. }
  282. DebugText.text = "Error code : 7-1";
  283. PlayerManager.InitDressRoom();
  284. DebugText.text = "Error code : 8";
  285. Manager.FirstTimeLoginCallback(new JsonData());
  286. //debugLab.text = "Error code : 9";
  287. //SFSManager.GardenSmartFox.Connector.Connect();
  288. DebugText.text = "Error code : 10";
  289. StringFilter.Init();
  290. DebugText.text = "Error code : 11";
  291. IAPManager.Init();
  292. DebugText.text = "Error code : 12";
  293. VisitManager.Init();
  294. DebugText.text = "Error code : 13";
  295. SocialManager.InitRankPanel();
  296. if (Instance.DebugMode)
  297. {
  298. ActivateGame();
  299. }
  300. else
  301. {
  302. ShowLoadingPanel();
  303. }
  304. }
  305. public IEnumerator WaitToInit()
  306. {
  307. while (!Logo.Complete)
  308. {
  309. yield return null;
  310. }
  311. while (!Bundle.Complete)
  312. {
  313. yield return null;
  314. }
  315. //EnableDebugLab();
  316. DebugText = GameObject.Find(CanvasLabel.U_DebugLab).GetComponent<Text>();
  317. //DebugText.text = "W3";
  318. Bundle.CopyAssetBundles();
  319. while (!Bundle.CopyComplete)
  320. {
  321. yield return null;
  322. }
  323. ResourceManager.Get(CanvasLabel.AJ_UpdatePanel).AddComponent<UpdatePanel>().Init();
  324. bool haveError = Bundle.UpdateAssetBundles();
  325. while (haveError)
  326. {
  327. yield return null;
  328. }
  329. //DebugText.text = "W4";
  330. while (!Bundle.UpdateComplete)
  331. {
  332. //DebugText.text = "W5";
  333. yield return null;
  334. }
  335. //UpdatePanel.Show();
  336. //while (true)
  337. //{
  338. // yield return null;
  339. //}
  340. //DebugText.text = "W5-2";
  341. SetWarningTitleAndText();
  342. //DebugText.text = "W6";
  343. while (ConfigManager.PlayerDocumentDamageFlag)
  344. {
  345. //DebugText.text = "W7";
  346. yield return null;
  347. }
  348. Language.Initialize();
  349. UIManager.Init(Instance.DebugMode);
  350. AudioManager.Init();
  351. InitEntrance();
  352. }
  353. private static float LoadingDelayTime = 3f;
  354. private static void ShowLoadingPanel()
  355. {
  356. DelayCall.Call(1, () =>
  357. {
  358. Canvas canvas = ResourceManager.Get(CanvasLabel.U_Parent).AddComponent<Canvas>();
  359. ResourceManager.Get(CanvasLabel.U_Parent).AddComponent<GraphicRaycaster>();
  360. canvas.overrideSorting = true;
  361. canvas.sortingOrder = 5;
  362. });
  363. ResourceManager.Get(CanvasLabel.U_Group).TweenForCG();
  364. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 0;
  365. ResourceManager.SetText(CanvasLabel.U_Lab, Language.GetStr(LanguageLabel.UI__U_Lab));
  366. Auxiliary.Instance.DelayCall(ActivateGame, LoadingDelayTime);
  367. }
  368. public static void SetWarningTitleAndText()
  369. {
  370. SystemLanguage language = Application.systemLanguage;
  371. if (Instance.AuditEdition)
  372. {
  373. language = SystemLanguage.ChineseSimplified;
  374. }
  375. ResourceManager.SetText(CanvasLabel.U_WarningTitle, Language.GetStr(LanguageLabel.UI__U_WarningTitle, language));
  376. if (language == SystemLanguage.ChineseSimplified)
  377. {
  378. ResourceManager.SetActive(CanvasLabel.U_WarningTitle, false);
  379. ResourceManager.SetText(CanvasLabel.U_WarningText, Language.GetStr(LanguageLabel.UI__U_WarningText, language));
  380. }
  381. else if (language == SystemLanguage.ChineseTraditional)
  382. {
  383. ResourceManager.SetActive(CanvasLabel.U_WarningTitle, false);
  384. ResourceManager.SetText(CanvasLabel.U_WarningText, Language.GetStr(LanguageLabel.UI__U_WarningText, language));
  385. }
  386. else
  387. {
  388. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  389. }
  390. }
  391. private static void ActivateGame()
  392. {
  393. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 1;
  394. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.U_LoadingPanel).TweenForCG();
  395. tweenRoot.AddEventOnetime
  396. (
  397. EventType.ForwardFinish,
  398. () => ResourceManager.Get(CanvasLabel.U_Icon).GetTweenEuler().Pause()
  399. );
  400. AudioManager.GardenThemeAudio.TweenForAudio();
  401. IsGameActivated = true;
  402. }
  403. public static void EnableDebugLab()
  404. {
  405. ResourceManager.Get<CanvasGroup>(CanvasLabel.U_Group).alpha = 0;
  406. ResourceManager.Get<Text>(CanvasLabel.U_DebugLab).enabled = true;
  407. }
  408. }