Initializer.cs 17 KB

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