GameApplction.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 GameUI;
  13. #if UNITY_EDITOR
  14. using UnityEditor;
  15. #endif
  16. using UnityEngine;
  17. using UnityEngine.UI;
  18. using Utility.CTween;
  19. using Utility.UITool;
  20. public class GameApplction : IGameStart
  21. {
  22. public ShaderVariantCollection ShaderVariantCollection;
  23. public BundleLoadType BundleLoadType;
  24. public string h5Url;
  25. private Entity _root;
  26. private Entity _scene;
  27. // public bool isTest;
  28. public int levelBattleId = 1;
  29. private GameStartUIPanel gameStartUIPanel;
  30. public async void StartGame(LoadType LoadType, string h5Url, GameStartUIPanel gameStartUIPanel,
  31. System.Action LoadFinish)
  32. {
  33. // UnityEngine.Screen.SetResolution(Screen.width);
  34. GameUpdateAsset.Instance.Init(h5Url);
  35. this.gameStartUIPanel = gameStartUIPanel;
  36. gameStartUIPanel.ShowMassge("开始加载资源");
  37. gameStartUIPanel.SetSlider(0);
  38. this.h5Url = h5Url;
  39. BundleLoadType = (BundleLoadType)LoadType;
  40. GameObject gameObject = new GameObject("app");
  41. gameObject.AddComponent<GameApplctionMono>();
  42. await InitGameApplication();
  43. LoadFinish?.Invoke();
  44. UIManager.Instance.Canvas.gameObject.SetActive(true);
  45. Debug.Log("初始化完成");
  46. }
  47. private async CTask InitGameApplication()
  48. {
  49. _scene = new Scene();
  50. _root = new Entity();
  51. _root.Parent = _scene;
  52. _root.AddComponent<TimerComponent>();
  53. _root.AddComponent<CoroutineLockComponent>();
  54. gameStartUIPanel.ShowMassge("loadBundle");
  55. gameStartUIPanel.SetSlider(0.15f);
  56. AssetBundleLoadManager.Instance.BundleLoadType = BundleLoadType;
  57. AssetBundleLoadManager.Instance.h5Url = h5Url;
  58. await AssetBundleLoadManager.Instance.InitAssetsManager(null);
  59. #if !UNITY_EDITOR
  60. AssetBundleLoadManager.Instance.AddBundleTask("fb010shader", delegate(BundleLoadBasic basic, object o)
  61. {
  62. if (basic.currBundle != null)
  63. {
  64. basic.currBundle.LoadAllAssets<Shader>();
  65. Shader.WarmupAllShadersWait();
  66. }
  67. }, null);
  68. #endif
  69. gameStartUIPanel.ShowMassge("loadConfig");
  70. gameStartUIPanel.SetSlider(0.25f);
  71. await ConfigComponent.Instance.Preload();
  72. await AnimationCurveManager.Instance.Init();
  73. UGUIPackLoad uguiPackLoad = new UGUIPackLoad();
  74. UGUIPackManager.Instance.SetIUGUIPackLoad(uguiPackLoad);
  75. await uguiPackLoad.InitPack();
  76. gameStartUIPanel.ShowMassge("loadLanguage");
  77. gameStartUIPanel.SetSlider(0.45f);
  78. await LanguageManager.Instance.InitManager();
  79. _root.AddComponent<StaticUpdater>();
  80. _root.AddComponent<UIManager, Transform>(null);
  81. gameStartUIPanel.ShowMassge("loadUI");
  82. gameStartUIPanel.SetSlider(0.55f);
  83. await AudioManager.Instance.InitMainAudio();
  84. await UIManager.Instance.InitUI();
  85. CustomTweenManager.Init();
  86. PlayerManager.Instance.Init();
  87. // PlayerManager.Instance.InitTestHero();
  88. //主UI加载
  89. MainSceneController.Instance.Init();
  90. await CombatDrive.Instance.Init();
  91. StartCombatInfo startCombatInfo = new StartCombatInfo();
  92. startCombatInfo.CombatType = CombatType.LevelBattle;
  93. #if UNITY_EDITOR
  94. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  95. if (testCombatHeroConfig != null)
  96. {
  97. startCombatInfo.CombatType = CombatType.TestCombat;
  98. }
  99. #endif
  100. startCombatInfo.levelBattleId = AccountFileInfo.Instance.playerData.levelBattle;
  101. CombatDrive.Instance.AddCombatController(new CombatController());
  102. gameStartUIPanel.ShowMassge("loadCombat");
  103. gameStartUIPanel.SetSlider(0.95f);
  104. await CombatDrive.Instance.StartCombat(startCombatInfo);
  105. gameStartUIPanel.ShowMassge("loadFinish");
  106. gameStartUIPanel.SetSlider(1f);
  107. }
  108. }