Initializer.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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.text = "Error code : 1";
  192. TutorialManager.NewplayerTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.NewplayerTutorial);
  193. DebugText.text = "Error code : 1-1";
  194. TutorialManager.memoryMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.MemoryMinigameTutorial);
  195. DebugText.text = "Error code : 1-2";
  196. TutorialManager.visitTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.VisitTutorial);
  197. DebugText.text = "Error code : 1-3";
  198. TutorialManager.dressroomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.DressroomTutorial);
  199. DebugText.text = "Error code : 1-4";
  200. TutorialManager.findSoloMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindSoloMinigameTutorial);
  201. DebugText.text = "Error code : 1-5";
  202. TutorialManager.findMissingMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindMissingMinigameTutorial);
  203. DebugText.text = "Error code : 1-5-0";
  204. TutorialManager.plazaRoomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.TutorialPlazaRoom);
  205. DebugText.text = "Error code : 1-5-1";
  206. TutorialManager.NewplayerTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.NewplayerTutorialIndex);
  207. DebugText.text = "Error code : 1-6";
  208. TutorialManager.MemoryMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.MemoryMinigameTutorialIndex);
  209. DebugText.text = "Error code : 1-7";
  210. TutorialManager.VisitTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.VisitTutorialIndex);
  211. DebugText.text = "Error code : 1-8";
  212. TutorialManager.DressroomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.DressroomIndex);
  213. DebugText.text = "Error code : 1-9";
  214. TutorialManager.FindSoloMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindSoloMinigameTutorialIndex);
  215. DebugText.text = "Error code : 1-10";
  216. TutorialManager.FindMissingMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindMissingMinigameTutorialIndex);
  217. DebugText.text = "Error code : 1-10-0";
  218. TutorialManager.PlazaRoomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.TutorialIndexPlazaRoom);
  219. DebugText.text = "Error code : 1-10-1";
  220. Bundle.LoadAtlasSprites();
  221. DebugText.text = "Error code : 1-11";
  222. //Bundle.LoadAllDressBundleAssetsIntoDragonbone();
  223. DebugText.text = "Error code : 1-11-1";
  224. for (int i = 0; i < RegistList.Count; i++)
  225. {
  226. DebugText.text = "Error code : 1-12-" + i;
  227. //Debug.Log(i + " " + RegistList[i].GetType());
  228. RegistList[i].InstantiatePrefabs();
  229. }
  230. DebugText.text = "Error code : 2";
  231. }
  232. public static void InitGame()
  233. {
  234. InstantiatePrefabs();
  235. for (int i = 0; i < RegistList.Count; i++)
  236. {
  237. DebugText.text = "Error code : 2-" + i;
  238. RegistList[i].RegistReference();
  239. }
  240. DebugText.text = "Error code : 3";
  241. for (int i = 0; i < RegistList.Count; i++)
  242. {
  243. DebugText.text = "Error code : 3-" + i;
  244. RegistList[i].FirstInit();
  245. }
  246. DebugText.text = "Error code : 4";
  247. for (int i = 0; i < RegistList.Count; i++)
  248. {
  249. DebugText.text = "Error code : 4-" + i;
  250. RegistList[i].SecondInit();
  251. }
  252. DebugText.text = "Error code : 5";
  253. for (int i = 0; i < RegistList.Count; i++)
  254. {
  255. DebugText.text = "Error code : 5-" + i;
  256. RegistList[i].ThirdInit();
  257. RegistList[i].enabled = true;
  258. }
  259. DebugText.text = "Error code : 6";
  260. Inited = true;
  261. if (HttpManager.IsAnnounceReady)
  262. {
  263. ResourceManager.SetActive(CanvasLabel.C_NotifyParent, true);
  264. ResourceManager.Get(CanvasLabel.C_Notify).TweenForCG();
  265. }
  266. DebugText.text = "Error code : 7";
  267. List<XmlAttributeCollection> attributeList = ConfigManager.GetDressRoomConfig();
  268. attributeList.RemoveAt(0);
  269. attributeList.AddRange(Bundle.NewDressroomConfigs);
  270. PlayerManager.CreateCloseItems(attributeList);
  271. DebugText.text = "Error code : 7-1";
  272. PlayerManager.InitDressRoom();
  273. DebugText.text = "Error code : 8";
  274. Manager.FirstTimeLoginCallback(new JsonData());
  275. //debugLab.text = "Error code : 9";
  276. //SFSManager.GardenSmartFox.Connector.Connect();
  277. DebugText.text = "Error code : 10";
  278. StringFilter.Init();
  279. DebugText.text = "Error code : 11";
  280. IAPManager.Init();
  281. DebugText.text = "Error code : 12";
  282. VisitManager.Init();
  283. DebugText.text = "Error code : 13";
  284. SocialManager.InitRankPanel();
  285. if (Instance.DebugMode)
  286. {
  287. ActivateGame();
  288. }
  289. else
  290. {
  291. ShowLoadingPanel();
  292. }
  293. }
  294. public IEnumerator WaitToInit()
  295. {
  296. while (!Logo.Complete)
  297. {
  298. yield return null;
  299. }
  300. while (!Bundle.Complete)
  301. {
  302. yield return null;
  303. }
  304. DebugText = GameObject.Find(CanvasLabel.U_DebugLab).GetComponent<Text>();
  305. Bundle.UpdateAssetBundle();
  306. while (!Bundle.UpdateComplete)
  307. {
  308. yield return null;
  309. }
  310. while (ConfigManager.PlayerDocumentDamageFlag)
  311. {
  312. yield return null;
  313. }
  314. Language.Initialize();
  315. UIManager.Init(Instance.DebugMode);
  316. AudioManager.Init();
  317. InitEntrance();
  318. }
  319. private static float LoadingDelayTime = 3f;
  320. private static void ShowLoadingPanel()
  321. {
  322. ResourceManager.Get(CanvasLabel.U_Group).TweenForCG();
  323. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 0;
  324. ResourceManager.SetText(CanvasLabel.U_Lab, Language.GetStr(LanguageLabel.UI__U_Lab));
  325. Auxiliary.Instance.DelayCall(ActivateGame, LoadingDelayTime);
  326. }
  327. public static void SetWarningTitleAndText()
  328. {
  329. SystemLanguage language = Application.systemLanguage;
  330. if (Instance.AuditEdition)
  331. {
  332. language = SystemLanguage.ChineseSimplified;
  333. }
  334. ResourceManager.SetText(CanvasLabel.U_WarningTitle, Language.GetStr(LanguageLabel.UI__U_WarningTitle, language));
  335. if (language == SystemLanguage.ChineseSimplified)
  336. {
  337. ResourceManager.SetText(CanvasLabel.U_WarningText, Language.GetStr(LanguageLabel.UI__U_WarningText, language));
  338. }
  339. else if (language == SystemLanguage.ChineseTraditional)
  340. {
  341. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  342. }
  343. else
  344. {
  345. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  346. }
  347. }
  348. private static void ActivateGame()
  349. {
  350. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 1;
  351. TweenRoot tweenRoot = ResourceManager.Get(CanvasLabel.U_LoadingPanel).TweenForCG();
  352. tweenRoot.AddEventOnetime
  353. (
  354. EventType.ForwardFinish,
  355. () => ResourceManager.Get(CanvasLabel.U_Icon).GetTweenEuler().Pause()
  356. );
  357. AudioManager.GardenThemeAudio.TweenForAudio();
  358. IsGameActivated = true;
  359. }
  360. public static void EnableDebugLab()
  361. {
  362. ResourceManager.Get<CanvasGroup>(CanvasLabel.U_Group).alpha = 0;
  363. ResourceManager.Get<Text>(CanvasLabel.U_DebugLab).enabled = true;
  364. }
  365. }