CombatController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Core.State;
  2. using Fort23.Core;
  3. using GameLogic.Combat.CombatState;
  4. using GameLogic.CombatScenesTool;
  5. using UnityEngine;
  6. namespace GameLogic.Combat.CombatTool
  7. {
  8. public class CombatController
  9. {
  10. public static CombatController currActiveCombat;
  11. public CombatHeroController CombatHeroController;
  12. public CombatCameraControllder CombatCameraControllder;
  13. protected StateControl stateControl;
  14. private AssetHandle scenesHandle;
  15. private CombatScenesConfig _combatScenesConfig;
  16. public bool isUpdate;
  17. private int _currIndex = 0;
  18. public CombatScenesNodeConfig nextConfig;
  19. public CombatStateBasic CurrState
  20. {
  21. get { return stateControl.CurrIState as CombatStateBasic; }
  22. }
  23. public async CTask InitCombat()
  24. {
  25. currActiveCombat = this;
  26. stateControl = new StateControl();
  27. stateControl.AddState("idle", new CombatIdleState(this));
  28. stateControl.AddState("update", new CombatUpdateState(this));
  29. scenesHandle =
  30. await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>("TestCombatScenes.prefab");
  31. GameObject gameObject = scenesHandle.AssetObject<GameObject>();
  32. gameObject.SetActive(true);
  33. _combatScenesConfig = gameObject.GetComponent<CombatScenesConfig>();
  34. nextConfig = _combatScenesConfig.allNodeConfig[_currIndex];
  35. Camera camera = gameObject.transform.GetComponentInChildren<Camera>();
  36. CombatCameraControllder = new CombatCameraControllder();
  37. CombatCameraControllder.Init(this, camera);
  38. CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
  39. CombatHeroController = new CombatHeroController();
  40. TestCombat(cTaskAwaitBuffer);
  41. await cTaskAwaitBuffer.WaitAll();
  42. ChangeState("update");
  43. isUpdate = true;
  44. }
  45. private void TestCombat(CTaskAwaitBuffer cTaskAwaitBuffer)
  46. {
  47. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  48. if (testCombatHeroConfig != null)
  49. {
  50. for (int i = 0; i < testCombatHeroConfig.myHeroInfo.Length; i++)
  51. {
  52. int index = i;
  53. CombatHeroInfo combatHeroInfo = testCombatHeroConfig.myHeroInfo[i];
  54. CombatHeroEntity heroEntity = new CombatHeroEntity();
  55. heroEntity.IsEnemy = false;
  56. cTaskAwaitBuffer.AddTask(heroEntity.Init(new CombatAIBasic(), combatHeroInfo,
  57. delegate(CombatHeroEntity entity)
  58. {
  59. CombatHeroController.AddHero(entity);
  60. heroEntity.combatHeroGameObject.SetPosition(nextConfig.heroStartPos.position);
  61. }));
  62. }
  63. for (int i = 0; i < testCombatHeroConfig.enemyHeroInfo.Length; i++)
  64. {
  65. int index = i;
  66. CombatHeroInfo combatHeroInfo = testCombatHeroConfig.enemyHeroInfo[i];
  67. CombatHeroEntity heroEntity = new CombatHeroEntity();
  68. heroEntity.IsEnemy = true;
  69. cTaskAwaitBuffer.AddTask(heroEntity.Init(new CombatAIBasic(), combatHeroInfo,
  70. delegate(CombatHeroEntity entity)
  71. {
  72. CombatHeroController.AddHero(entity);
  73. heroEntity.combatHeroGameObject.SetPosition(nextConfig.monsterPoint[index].position);
  74. ;
  75. }));
  76. }
  77. }
  78. }
  79. public void ChangeState(string name)
  80. {
  81. stateControl.ChangeState(name);
  82. }
  83. public void Update(float t)
  84. {
  85. if (!isUpdate)
  86. {
  87. return;
  88. }
  89. stateControl.Update(t);
  90. }
  91. }
  92. }