Initializer.cs 15 KB

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