Initializer.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. Instantiate(DebugModeGo, transform);
  102. }
  103. else
  104. {
  105. gameObject.AddComponent<Bundle>();
  106. }
  107. InitScriptProgress = index++.ToString();
  108. gameObject.AddComponent<IAPManager>();
  109. InitScriptProgress = index++.ToString();
  110. gameObject.AddComponent<VisitManager>();
  111. InitScriptProgress = index++.ToString();
  112. gameObject.AddComponent<DebugManager>();
  113. InitScriptProgress = index++.ToString();
  114. gameObject.AddScript<Auxiliary>();
  115. InitScriptProgress = index++.ToString();
  116. gameObject.AddScript<ConfigManager>();
  117. InitScriptProgress = index++.ToString();
  118. gameObject.AddScript<ResourceManager>();
  119. InitScriptProgress = index++.ToString();
  120. gameObject.AddScript<TutorialManager>();
  121. InitScriptProgress = index++.ToString();
  122. gameObject.AddScript<LanguageManager>();
  123. InitScriptProgress = index++.ToString();
  124. gameObject.AddScript<AnimManager>();
  125. InitScriptProgress = index++.ToString();
  126. gameObject.AddScript<AudioManager>();
  127. InitScriptProgress = index++.ToString();
  128. gameObject.AddScript<AchieveManager>();
  129. InitScriptProgress = index++.ToString();
  130. gameObject.AddScript<UIManager>();
  131. InitScriptProgress = index++.ToString();
  132. gameObject.AddScript<SignManager>();
  133. InitScriptProgress = index++.ToString();
  134. gameObject.AddScript<Manager>();
  135. InitScriptProgress = index++.ToString();
  136. gameObject.AddScript<GardenManager>();
  137. InitScriptProgress = index++.ToString();
  138. gameObject.AddScript<PlayerManager>();
  139. InitScriptProgress = index++.ToString();
  140. gameObject.AddScript<HttpManager>();
  141. InitScriptProgress = index++.ToString();
  142. gameObject.AddScript<MiniGameManager>();
  143. InitScriptProgress = index++.ToString();
  144. gameObject.AddScript<InfoBoxManager>();
  145. InitScriptProgress = index++.ToString();
  146. gameObject.AddScript<SocialManager>();
  147. InitScriptProgress = index++.ToString();
  148. gameObject.AddScript<NickNameManager>();
  149. InitScriptProgress = index++.ToString();
  150. gameObject.AddScript<SFSManager>();
  151. InitScriptProgress = index++.ToString();
  152. gameObject.AddScript<PlazaRoomManager>();
  153. InitScriptProgress = index++.ToString();
  154. gameObject.AddScript<ChestManager>();
  155. InitScriptProgress = index++.ToString();
  156. gameObject.AddScript<RobotManager>();
  157. InitScriptProgress = index++.ToString();
  158. gameObject.AddScript<CDMinigamePanelManager>();
  159. InitScriptProgress = index++.ToString();
  160. gameObject.AddScript<EnterMinigamePanelManager>();
  161. InitScriptProgress = index++.ToString();
  162. gameObject.AddScript<PlazaroomMemberPanel>();
  163. InitScriptProgress = index++.ToString();
  164. gameObject.AddScript<FriendPanel>();
  165. InitScriptProgress = index++.ToString();
  166. gameObject.AddScript<AddFriendPanel>();
  167. InitScriptProgress = index++.ToString();
  168. gameObject.AddScript<MessagePanel>();
  169. InitScriptProgress = index++.ToString();
  170. gameObject.AddScript<FashionShowEditPage>();
  171. InitScriptProgress = index++.ToString();
  172. gameObject.AddScript<FashionShowCommentPanel>();
  173. InitScriptProgress = index++.ToString();
  174. gameObject.AddScript<FashionShowHomePage>();
  175. InitScriptProgress = index++.ToString();
  176. StartCoroutine(WaitToInit());
  177. }
  178. public static void InitEntrance()
  179. {
  180. if (Instance.CatchException)
  181. {
  182. DebugManager.TryCatch(InitGame, EnableDebugLab);
  183. }
  184. else
  185. {
  186. InitGame();
  187. }
  188. }
  189. public static void InstantiatePrefabs()
  190. {
  191. DebugText = GameObject.Find(CanvasLabel.U_DebugLab).GetComponent<Text>();
  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. PlayerManager.InitDressRoom();
  269. DebugText.text = "Error code : 8";
  270. Manager.FirstTimeLoginCallback(new JsonData());
  271. //debugLab.text = "Error code : 9";
  272. //SFSManager.GardenSmartFox.Connector.Connect();
  273. DebugText.text = "Error code : 10";
  274. StringFilter.Init();
  275. DebugText.text = "Error code : 11";
  276. IAPManager.Init();
  277. DebugText.text = "Error code : 12";
  278. VisitManager.Init();
  279. DebugText.text = "Error code : 13";
  280. SocialManager.InitRankPanel();
  281. if (Instance.DebugMode)
  282. {
  283. ActivateGame();
  284. }
  285. else
  286. {
  287. ShowLoadingPanel();
  288. }
  289. }
  290. public IEnumerator WaitToInit()
  291. {
  292. while (!Logo.Complete)
  293. {
  294. yield return null;
  295. }
  296. while (!Bundle.Complete)
  297. {
  298. yield return null;
  299. }
  300. while (ConfigManager.PlayerDocumentDamageFlag)
  301. {
  302. yield return null;
  303. }
  304. UIManager.Init(Instance.DebugMode);
  305. AudioManager.Init();
  306. InitEntrance();
  307. }
  308. private static float LoadingDelayTime = 3f;
  309. private static void ShowLoadingPanel()
  310. {
  311. ResourceManager.Get(CanvasLabel.U_Group).TweenForCG();
  312. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 0;
  313. ResourceManager.SetText(CanvasLabel.U_Lab, Language.GetStr(LanguageLabel.UI__U_Lab));
  314. Auxiliary.Instance.DelayCall(ActivateGame, LoadingDelayTime);
  315. }
  316. public static void SetWarningTitleAndText()
  317. {
  318. SystemLanguage language = Application.systemLanguage;
  319. if (Instance.AuditEdition)
  320. {
  321. language = SystemLanguage.ChineseSimplified;
  322. }
  323. ResourceManager.SetText(CanvasLabel.U_WarningTitle, Language.GetStr(LanguageLabel.UI__U_WarningTitle, language));
  324. if (language == SystemLanguage.ChineseSimplified)
  325. {
  326. ResourceManager.SetText(CanvasLabel.U_WarningText, Language.GetStr(LanguageLabel.UI__U_WarningText, language));
  327. }
  328. else if (language == SystemLanguage.ChineseTraditional)
  329. {
  330. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  331. }
  332. else
  333. {
  334. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  335. }
  336. }
  337. private static void ActivateGame()
  338. {
  339. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 1;
  340. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.U_LoadingPanel).TweenForCG();
  341. tweenRoot.AddEventOnetime
  342. (
  343. EventType.ForwardFinish,
  344. () => ResourceManager.Get(CanvasLabel.U_Icon).GetTweenEuler().Pause()
  345. );
  346. AudioManager.GardenThemeAudio.TweenForAudio();
  347. IsGameActivated = true;
  348. }
  349. public static void EnableDebugLab()
  350. {
  351. ResourceManager.Get<CanvasGroup>(CanvasLabel.U_Group).alpha = 0;
  352. ResourceManager.Get<Text>(CanvasLabel.U_DebugLab).enabled = true;
  353. }
  354. }