Initializer.cs 12 KB

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