GameApplction.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using Core.AssetLoadTool.Asset;
  2. using Core.Audio;
  3. using Core.Language;
  4. using Fort23.Core;
  5. using Fort23.Mono;
  6. using Fort23.Mono.UpdateAsset;
  7. using Fort23.UTool;
  8. using GameLogic.Combat;
  9. using GameLogic.Combat.CombatTool;
  10. using GameLogic.Combat.CombatType;
  11. using GameLogic.CombatScenesTool;
  12. using GameLogic.NetworkClient;
  13. using GameUI;
  14. using NetCore.Protocol.MemoryPack;
  15. #if UNITY_EDITOR
  16. using UnityEditor;
  17. #endif
  18. using UnityEngine;
  19. using UnityEngine.UI;
  20. using Utility.CTween;
  21. using Utility.UITool;
  22. public class GameApplction : IGameStart
  23. {
  24. public ShaderVariantCollection ShaderVariantCollection;
  25. public BundleLoadType BundleLoadType;
  26. public string h5Url;
  27. private Entity _root;
  28. private Entity _scene;
  29. // public bool isTest;
  30. public int levelBattleId = 1;
  31. private GameStartUIPanel gameStartUIPanel;
  32. public async void StartGame(LoadType LoadType, string h5Url, GameStartUIPanel gameStartUIPanel,
  33. System.Action LoadFinish)
  34. {
  35. Debug.Log("开始游戏逻辑");
  36. // UnityEngine.Screen.SetResolution(Screen.width);
  37. GameUpdateAsset.Instance.Init(h5Url);
  38. this.gameStartUIPanel = gameStartUIPanel;
  39. gameStartUIPanel.ShowMassge("开始加载资源");
  40. gameStartUIPanel.SetSlider(0);
  41. this.h5Url = h5Url;
  42. BundleLoadType = (BundleLoadType)LoadType;
  43. GameObject gameObject = new GameObject("app");
  44. gameObject.AddComponent<GameApplctionMono>();
  45. await InitGameApplication();
  46. LoadFinish?.Invoke();
  47. UIManager.Instance.Canvas.gameObject.SetActive(true);
  48. Debug.Log("初始化完成");
  49. }
  50. private async CTask InitGameApplication()
  51. {
  52. _scene = new Scene();
  53. _root = new Entity();
  54. _root.Parent = _scene;
  55. _root.AddComponent<TimerComponent>();
  56. _root.AddComponent<CoroutineLockComponent>();
  57. gameStartUIPanel.ShowMassge("loadBundle");
  58. gameStartUIPanel.SetSlider(0.15f);
  59. AssetBundleLoadManager.Instance.BundleLoadType = BundleLoadType;
  60. AssetBundleLoadManager.Instance.h5Url = h5Url;
  61. await AssetBundleLoadManager.Instance.InitAssetsManager(null);
  62. #if !UNITY_EDITOR
  63. AssetBundleLoadManager.Instance.AddBundleTask("fb010shader", delegate(BundleLoadBasic basic, object o)
  64. {
  65. if (basic.currBundle != null)
  66. {
  67. basic.currBundle.LoadAllAssets<Shader>();
  68. Shader.WarmupAllShadersWait();
  69. }
  70. }, null);
  71. #endif
  72. gameStartUIPanel.ShowMassge("loadConfig");
  73. gameStartUIPanel.SetSlider(0.25f);
  74. await ConfigComponent.Instance.Preload();
  75. await AnimationCurveManager.Instance.Init();
  76. UGUIPackLoad uguiPackLoad = new UGUIPackLoad();
  77. UGUIPackManager.Instance.SetIUGUIPackLoad(uguiPackLoad);
  78. await uguiPackLoad.InitPack();
  79. gameStartUIPanel.ShowMassge("loadLanguage");
  80. gameStartUIPanel.SetSlider(0.45f);
  81. await LanguageManager.Instance.InitManager();
  82. _root.AddComponent<StaticUpdater>();
  83. _root.AddComponent<UIManager, Transform>(null);
  84. gameStartUIPanel.ShowMassge("loadUI");
  85. gameStartUIPanel.SetSlider(0.55f);
  86. await AudioManager.Instance.InitMainAudio();
  87. await UIManager.Instance.InitUI();
  88. CustomTweenManager.Init();
  89. // await GameNetworkClient.Instance.Connect("127.0.0.1", 1000);
  90. await Login();
  91. }
  92. private async CTask Login()
  93. {
  94. // MemoryResponse memoryResponse = await GameNetworkSendAssemble.SendLogin("123", "123");
  95. // if (memoryResponse == null)
  96. // {
  97. // LogTool.Error("登陆失败");
  98. // return;
  99. // }
  100. PlayerManager.Instance.Init();
  101. // PlayerManager.Instance.InitTestHero();
  102. await CombatDrive.Instance.Init();
  103. StartCombatInfo startCombatInfo = new StartCombatInfo();
  104. startCombatInfo.CombatType = CombatType.LevelBattle;
  105. #if UNITY_EDITOR
  106. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  107. if (testCombatHeroConfig != null)
  108. {
  109. startCombatInfo.CombatType = CombatType.TestCombat;
  110. }
  111. #endif
  112. startCombatInfo.levelBattleId = AccountFileInfo.Instance.playerData.levelBattle;
  113. CombatDrive.Instance.AddCombatController(new CombatController());
  114. gameStartUIPanel.ShowMassge("loadCombat");
  115. gameStartUIPanel.SetSlider(0.95f);
  116. await CombatDrive.Instance.StartCombat(startCombatInfo);
  117. gameStartUIPanel.ShowMassge("loadFinish");
  118. gameStartUIPanel.SetSlider(1f);
  119. }
  120. }