CombatHeroEntity.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Animancer;
  4. using Common.Utility.CombatEvent;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Combat.CombatTool;
  8. using GameLogic.Combat.Hero;
  9. using UnityEngine;
  10. using UnityEngine.AI;
  11. using UnityEngine.Rendering;
  12. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  13. public class CombatHeroEntity : ITimeLineSpecialDotPos, ILifeCycle, ITimeLineAnimtion, ITimeLineGetAttSpeed
  14. {
  15. public bool IsEnemy;
  16. public bool isDie;
  17. public CombatAIBasic CombatAIBasic;
  18. public CombatHeroGameObject combatHeroGameObject;
  19. public CombatHeroInfo CurrCombatHeroInfo;
  20. public CombatHeroInfo MaxCombatHeroInfo;
  21. public CombatHeroTimeLineControl combatHeroTimeLineControl;
  22. public CombatHeroAnimtion combatHeroAnimtion;
  23. public CombatHeroSkillControl CombatHeroSkillControl;
  24. public Vector3 dotPos
  25. {
  26. get { return combatHeroGameObject.position; }
  27. }
  28. public Vector3 faceDir { get; }
  29. public async CTask<CombatHeroEntity> Init(CombatAIBasic combatAIBasic, CombatHeroInfo combatHeroInfo,
  30. System.Action<CombatHeroEntity> callBack = null)
  31. {
  32. //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载
  33. GameObjectPool poolInterface =
  34. await GObjectPool.Instance.FetchAsync<GameObjectPool>(combatHeroInfo.modelName + ".prefab", null);
  35. #if !COMBAT_SERVER
  36. if (poolInterface == null || poolInterface.own == null)
  37. {
  38. return null;
  39. }
  40. poolInterface.own.SetActive(false);
  41. AssetHandle assetHandle =
  42. await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<TextAsset>(combatHeroInfo.modelName + "_TD.txt");
  43. TextAsset textAsset = assetHandle.AssetObject<TextAsset>();
  44. TimeLienData timeLienData = JsonManager.FromJson<TimeLienData>(textAsset.text);
  45. timeLienData.DeserializeData();
  46. assetHandle.Release();
  47. combatHeroTimeLineControl = new CombatHeroTimeLineControl();
  48. combatHeroTimeLineControl.Init(timeLienData);
  49. combatHeroGameObject = new CombatHeroGameObject();
  50. combatHeroGameObject.Init(this, poolInterface);
  51. NavMeshAgent navMeshAgent = poolInterface.own.GetComponent<NavMeshAgent>();
  52. if (combatAIBasic == null)
  53. {
  54. combatAIBasic = new CombatAIBasic();
  55. }
  56. HeroEntityMono heroEntityMono = poolInterface.own.GetComponent<HeroEntityMono>();
  57. if (heroEntityMono == null)
  58. {
  59. heroEntityMono = poolInterface.own.AddComponent<HeroEntityMono>();
  60. }
  61. heroEntityMono.combatHeroEntity = this;
  62. CombatAIBasic = combatAIBasic;
  63. CombatAIBasic.Init(this, navMeshAgent);
  64. CurrCombatHeroInfo = combatHeroInfo.Copy();
  65. MaxCombatHeroInfo = combatHeroInfo.Copy();
  66. CombatHeroSkillControl = new CombatHeroSkillControl();
  67. CombatHeroSkillControl.Init(this);
  68. AnimancerComponent animancerComponent = poolInterface.own.GetComponent<AnimancerComponent>();
  69. combatHeroAnimtion = new CombatHeroAnimtion();
  70. combatHeroAnimtion.Init(animancerComponent,this);
  71. CombatAIBasic.ChangeState(CombatHeroStateType.idle);
  72. CreateHeroHpEventData createHeroHpEventData = CreateHeroHpEventData.Create();
  73. createHeroHpEventData.combatHeroEntity = this;
  74. EventManager.Instance.Dispatch(CustomEventType.CreateHeroHp, createHeroHpEventData);
  75. poolInterface.own.SetActive(true);
  76. callBack?.Invoke(this);
  77. #endif
  78. return this;
  79. }
  80. public void Update(float t)
  81. {
  82. CombatAIBasic.Update(t);
  83. CombatHeroSkillControl.Update(t);
  84. combatHeroTimeLineControl.Update(t);
  85. }
  86. public T This<T>()
  87. {
  88. return (T)(object)this;
  89. }
  90. public T GetILifetCycleHitPoint<T>(string hitPoinName, bool isStandType, bool isIgnoreHind)
  91. where T : ILifetCycleHitPoint
  92. {
  93. return combatHeroGameObject.GetILifetCycleHitPoint<T>(hitPoinName, isStandType, isIgnoreHind);
  94. }
  95. public T GetMainHotPoin<T>(bool isIgnoreHind = false) where T : ILifetCycleHitPoint
  96. {
  97. return combatHeroGameObject.GetMainHotPoin<T>(isIgnoreHind);
  98. }
  99. public void PlayAnim(string animName, bool isLoop, int layerId, bool repeat, float speed)
  100. {
  101. combatHeroAnimtion.Play(animName, speed);
  102. }
  103. public SpecialDotInfo GetSpecialDotInfo(string specialDotName)
  104. {
  105. return combatHeroGameObject.GetMainHotPoin<CombatHeroHitPoint>(false).GetSpecialDotInfo(specialDotName);
  106. }
  107. public float GetAttSpeed()
  108. {
  109. return CombatHeroSkillControl.NormalAttSpeedScale;
  110. }
  111. public void HeroDie(HarmReturnInfo harmReturnInfo)
  112. {
  113. isDie = true;
  114. HeroDieEventData heroDieEventData = HeroDieEventData.Create();
  115. heroDieEventData.combatHeroEntity = this;
  116. heroDieEventData.HarmReturnInfo = harmReturnInfo;
  117. CombatEventManager.Instance.Dispatch(CombatEventType.HeroDie, heroDieEventData);
  118. combatHeroGameObject.HeroDie();
  119. CombatAIBasic.ChangeState(CombatHeroStateType.dile);
  120. }
  121. public void HeroHurt(HarmReturnInfo harmReturnInfo)
  122. {
  123. CurrCombatHeroInfo.hp -= harmReturnInfo.att;
  124. HarmUpdateEventData harmUpdateEventData= HarmUpdateEventData.Create();
  125. harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
  126. CombatEventManager.Instance.Dispatch(CombatEventType.HarmUpdate, harmUpdateEventData);
  127. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  128. heroHpUpdateEventData.combatHeroEntity = this;
  129. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  130. if (CurrCombatHeroInfo.hp <= 0)
  131. {
  132. HeroDie(harmReturnInfo);
  133. }
  134. }
  135. public void Dispose()
  136. {
  137. CombatHeroSkillControl.Dispose();
  138. combatHeroGameObject.Dispose();
  139. CombatAIBasic.Dispose();
  140. combatHeroTimeLineControl.Dispose();
  141. combatHeroAnimtion.Dispose();
  142. }
  143. }