Initializer.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 bool DebugMode;
  19. public bool CatchException;
  20. public GameObject DebugModeGo;
  21. public static bool Inited;
  22. public static Text DebugText;
  23. public static Initializer Instance;
  24. public static List<Regist> RegistList = new List<Regist>();
  25. #endregion
  26. private void Awake()
  27. {
  28. try
  29. {
  30. InitDataEye();
  31. }
  32. catch (Exception)
  33. {
  34. }
  35. string progress = "";
  36. try
  37. {
  38. progress = "1";
  39. Application.targetFrameRate = 50;
  40. progress = "2";
  41. DontDestroyOnLoad(gameObject);
  42. progress = "3";
  43. HttpManager.Login(Manager.FirstTimeLoginCallback);
  44. progress = "4";
  45. HttpManager.GetMailAwardData();
  46. progress = "5";
  47. HttpManager.GetRankData();
  48. progress = "6";
  49. HttpManager.GetAlipayFlag();
  50. progress = "7";
  51. HttpManager.GetAnnounceData();
  52. Instance = this;
  53. progress = "8";
  54. if (DebugMode)
  55. {
  56. Instantiate(DebugModeGo, transform);
  57. }
  58. else
  59. {
  60. gameObject.AddComponent<Bundle>();
  61. }
  62. progress = "9";
  63. gameObject.AddComponent<IAPManager>();
  64. progress = "10";
  65. gameObject.AddComponent<VisitManager>();
  66. progress = "11";
  67. gameObject.AddComponent<DebugManager>();
  68. progress = "12";
  69. gameObject.AddScript<Auxiliary>();
  70. progress = "13";
  71. gameObject.AddScript<ConfigManager>();
  72. progress = "14";
  73. gameObject.AddScript<ResourceManager>();
  74. progress = "15";
  75. gameObject.AddScript<TutorialManager>();
  76. progress = "16";
  77. gameObject.AddScript<LanguageManager>();
  78. progress = "17";
  79. gameObject.AddScript<AnimManager>();
  80. progress = "18";
  81. gameObject.AddScript<AudioManager>();
  82. progress = "19";
  83. gameObject.AddScript<AchieveManager>();
  84. progress = "20";
  85. gameObject.AddScript<UIManager>();
  86. progress = "21";
  87. gameObject.AddScript<SignManager>();
  88. progress = "22";
  89. gameObject.AddScript<Manager>();
  90. progress = "23";
  91. gameObject.AddScript<GardenManager>();
  92. progress = "24";
  93. gameObject.AddScript<PlayerManager>();
  94. progress = "25";
  95. gameObject.AddScript<HttpManager>();
  96. progress = "26";
  97. gameObject.AddScript<MiniGameManager>();
  98. progress = "27";
  99. gameObject.AddScript<InfoBoxManager>();
  100. progress = "28";
  101. gameObject.AddScript<SocialManager>();
  102. progress = "29";
  103. gameObject.AddScript<NickNameManager>();
  104. progress = "30";
  105. gameObject.AddScript<SFSManager>();
  106. progress = "31";
  107. gameObject.AddScript<PlazaRoomManager>();
  108. progress = "31-1";
  109. gameObject.AddScript<ChestManager>();
  110. progress = "31-2";
  111. gameObject.AddScript<RobotManager>();
  112. progress = "32";
  113. StartCoroutine(WaitToInit());
  114. }
  115. catch (Exception e)
  116. {
  117. Text debugText = GameObject.Find(LogoSceneLabel.DebugText).GetComponent<Text>();
  118. debugText.SetAlpha(1);
  119. debugText.text = progress + "\n" + e;
  120. throw new Exception();
  121. }
  122. }
  123. public static void InitEntrance()
  124. {
  125. if (Instance.CatchException)
  126. {
  127. DebugManager.TryCatch(Init, EnableDebugLab);
  128. }
  129. else
  130. {
  131. Init();
  132. }
  133. }
  134. public static void Init()
  135. {
  136. DebugText = GameObject.Find(ObjectLabel.U_DebugLab).GetComponent<Text>();
  137. DebugText.text = "Error code : 1";
  138. TutorialManager.NewplayerTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.NewplayerTutorial);
  139. DebugText.text = "Error code : 1-1";
  140. TutorialManager.memoryMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.MemoryMinigameTutorial);
  141. DebugText.text = "Error code : 1-2";
  142. TutorialManager.visitTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.VisitTutorial);
  143. DebugText.text = "Error code : 1-3";
  144. TutorialManager.dressroomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.DressroomTutorial);
  145. DebugText.text = "Error code : 1-4";
  146. TutorialManager.findMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindMinigameTutorial);
  147. DebugText.text = "Error code : 1-5";
  148. TutorialManager.plazaRoomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.TutorialPlazaRoom);
  149. DebugText.text = "Error code : 1-5-1";
  150. TutorialManager.NewplayerTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.NewplayerTutorialIndex);
  151. DebugText.text = "Error code : 1-6";
  152. TutorialManager.MemoryMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.MemoryMinigameTutorialIndex);
  153. DebugText.text = "Error code : 1-7";
  154. TutorialManager.VisitTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.VisitTutorialIndex);
  155. DebugText.text = "Error code : 1-8";
  156. TutorialManager.DressroomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.DressroomIndex);
  157. DebugText.text = "Error code : 1-9";
  158. TutorialManager.FindMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindMinigameTutorialIndex);
  159. DebugText.text = "Error code : 1-10";
  160. TutorialManager.PlazaRoomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.TutorialIndexPlazaRoom);
  161. DebugText.text = "Error code : 1-10-1";
  162. Bundle.LoadAtlasSprites();
  163. DebugText.text = "Error code : 1-11";
  164. for (int i = 0; i < RegistList.Count; i++)
  165. {
  166. DebugText.text = "Error code : 1-12-" + i;
  167. //Debug.Log(i + " " + RegistList[i].GetType());
  168. RegistList[i].InstantiatePrefabs();
  169. }
  170. DebugText.text = "Error code : 2";
  171. for (int i = 0; i < RegistList.Count; i++)
  172. {
  173. DebugText.text = "Error code : 2-" + i;
  174. RegistList[i].RegistReference();
  175. }
  176. DebugText.text = "Error code : 3";
  177. for (int i = 0; i < RegistList.Count; i++)
  178. {
  179. DebugText.text = "Error code : 3-" + i;
  180. RegistList[i].FirstInit();
  181. }
  182. DebugText.text = "Error code : 4";
  183. for (int i = 0; i < RegistList.Count; i++)
  184. {
  185. DebugText.text = "Error code : 4-" + i;
  186. RegistList[i].SecondInit();
  187. }
  188. DebugText.text = "Error code : 5";
  189. for (int i = 0; i < RegistList.Count; i++)
  190. {
  191. DebugText.text = "Error code : 5-" + i;
  192. RegistList[i].ThirdInit();
  193. RegistList[i].enabled = true;
  194. }
  195. DebugText.text = "Error code : 6";
  196. Inited = true;
  197. if (HttpManager.IsAnnounceReady)
  198. {
  199. ResourceManager.Get(ObjectLabel.C_Notify).TweenForCG();
  200. }
  201. DebugText.text = "Error code : 7";
  202. PlayerManager.InitDressRoom();
  203. DebugText.text = "Error code : 8";
  204. Manager.FirstTimeLoginCallback(new JsonData());
  205. //debugLab.text = "Error code : 9";
  206. //SFSManager.GardenSmartFox.Connector.Connect();
  207. DebugText.text = "Error code : 10";
  208. StringFilter.Init();
  209. DebugText.text = "Error code : 11";
  210. IAPManager.Init();
  211. DebugText.text = "Error code : 12";
  212. VisitManager.Init();
  213. DebugText.text = "Error code : 13";
  214. SocialManager.InitRankPanel();
  215. if (Instance.DebugMode)
  216. {
  217. ActivateGame();
  218. }
  219. else
  220. {
  221. ShowLoadingPanel();
  222. }
  223. }
  224. private void InitDataEye()
  225. {
  226. if (Application.platform == RuntimePlatform.IPhonePlayer)
  227. {
  228. DataEyeGA.Init("C5790DBD2CFE97BD18C7BE9A95482C05", DataEyeGA.PlatformType.IOS, "Official", "IOS");
  229. }
  230. else if (Application.isMobilePlatform)
  231. {
  232. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.ADR, "Official", "Android");
  233. }
  234. else if (Application.isEditor)
  235. {
  236. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.WP, "Official", "Windows");
  237. }
  238. }
  239. public IEnumerator WaitToInit()
  240. {
  241. while (!Logo.Complete)
  242. {
  243. yield return null;
  244. }
  245. while (!Bundle.Complete)
  246. {
  247. yield return null;
  248. }
  249. while (ConfigManager.PlayerDocumentDamageFlag)
  250. {
  251. yield return null;
  252. }
  253. InitEntrance();
  254. }
  255. private static float LoadingDelayTime = 3f;
  256. private static void ShowLoadingPanel()
  257. {
  258. ResourceManager.Get(ObjectLabel.U_Group).TweenForCG();
  259. ResourceManager.Get<CanvasGroup>(ObjectLabel.C_Main).alpha = 0;
  260. Auxiliary.Instance.DelayCall(ActivateGame, LoadingDelayTime);
  261. }
  262. private static void ActivateGame()
  263. {
  264. ResourceManager.Get(ObjectLabel.U_LoadingPanel).TweenForCG();
  265. ResourceManager.Get<CanvasGroup>(ObjectLabel.C_Main).alpha = 1;
  266. AudioManager.GardenThemeAudio.TweenForAudio();
  267. }
  268. public static void EnableDebugLab()
  269. {
  270. ResourceManager.Get<CanvasGroup>(ObjectLabel.U_Group).alpha = 0;
  271. ResourceManager.Get<Text>(ObjectLabel.U_DebugLab).enabled = true;
  272. }
  273. }