CombatHeroEntity.cs 6.0 KB

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