Initializer.cs 15 KB

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