FxParabolaBulletLogic.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System.Collections.Generic;
  2. using Core.Audio;
  3. using Core.Triiger;
  4. using GameLogic.Combat.CombatTool;
  5. using GameLogic.Combat.Hero;
  6. using GameLogic.Combat.Skill;
  7. using UnityEngine;
  8. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  9. namespace Common.Combat.FxAILogic
  10. {
  11. [AddComponentMenu("特效脚本/弹道/功法通用弹道")]
  12. public class FxParabolaBulletLogic : FxAILogicBasic
  13. {
  14. public float speed;
  15. private IUnRegister UnRegister = null;
  16. [Header("释放碰撞到地面时结束")] public bool isTriggerGroundEnd;
  17. [Header("碰撞到地面时的特效")] public string GroundHitFxName;
  18. private Vector3 endPos;
  19. private Vector3 dir;
  20. public float maxDis = 20;
  21. protected float maxDisSpr;
  22. // private BesselPath _besselPath;
  23. private float _addTime;
  24. protected Vector3 startDir;
  25. private float dirLerpTime;
  26. protected override void ProInit()
  27. {
  28. maxDisSpr = maxDis * maxDis;
  29. UnRegister = gameObject.OnTriggerEnterEvent(this, OnTriggerEnterEvent);
  30. if (isUseCustomTargetEndPos)
  31. {
  32. endPos = TimeLineEventParticleLogicBasic.customizePos[
  33. customTargetEndPosIndex];
  34. }
  35. else
  36. {
  37. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  38. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  39. }
  40. Vector3 off = _currPos - CombatHeroEntity.GameObject.transform.position;
  41. startDir = CombatHeroEntity.GameObject.transform.TransformPoint(off +
  42. new Vector3(
  43. Mathf.Sign(Random.Range(-1, 1) * 0.5f),
  44. Random.Range(0.1f, 0.3f), 0));
  45. startDir = (startDir - _currPos).normalized;
  46. dirLerpTime = 0;
  47. // dir = (endPos - CurrPos).normalized;
  48. // gameObject.transform.rotation = Quaternion.LookRotation(dir);
  49. }
  50. void TriggerGround()
  51. {
  52. ITimeLineTriggerEvent timeLineTriggerEvent =
  53. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  54. FinishHit(new Vector3(_currPos.x, 0.5f, _currPos.z), GroundHitFxName);
  55. AudioManager.Instance.PlayAudio(hitAudioName, false);
  56. if (timeLineTriggerEvent != null)
  57. {
  58. timeLineTriggerEvent.TimeLineTriggerGround(
  59. TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  60. this, triggerData);
  61. }
  62. AudioManager.Instance.PlayAudio(hitAudioName, false);
  63. Dispose();
  64. }
  65. protected void GetTargetPos()
  66. {
  67. if (isUseCustomTargetEndPos)
  68. {
  69. endPos = TimeLineEventParticleLogicBasic.customizePos[
  70. customTargetEndPosIndex];
  71. }
  72. else
  73. {
  74. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  75. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  76. }
  77. }
  78. protected void OnTriggerEnterEvent(Collider collision, ITriggerEntity triggerEntity)
  79. {
  80. if (isTriggerGroundEnd)
  81. {
  82. if (collision.gameObject.CompareTag("dimian"))
  83. {
  84. TriggerGround();
  85. return;
  86. }
  87. }
  88. FxAILogicBasic fxAILogicBasic = triggerEntity as FxAILogicBasic;
  89. if (fxAILogicBasic != null) //击中其他的功法
  90. {
  91. SkillFeaturesData skillFeaturesData = fxAILogicBasic.SkillFeaturesData;
  92. int myRestrained = SkillFeaturesData.GetRestrained(skillFeaturesData.SkillFeaturesType);
  93. int targetRestrained = skillFeaturesData.GetRestrained(SkillFeaturesData.SkillFeaturesType);
  94. int c = myRestrained - targetRestrained;
  95. int myHp = SkillFeaturesData.hp;
  96. int targetHp = skillFeaturesData.hp;
  97. if (c < 0) //我被压制
  98. {
  99. myHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(myHp, 10 * (Mathf.Abs(c)));
  100. }
  101. else if (c > 0)
  102. {
  103. targetHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(targetHp, 10 * (Mathf.Abs(c)));
  104. }
  105. if (myHp > targetHp)
  106. {
  107. myHp -= targetHp;
  108. SkillFeaturesData.hp = myHp;
  109. fxAILogicBasic.Dispose();
  110. }
  111. else if (myHp < targetHp)
  112. {
  113. targetHp -= myHp;
  114. skillFeaturesData.hp = targetHp;
  115. Dispose();
  116. }
  117. else if (myHp == targetHp)
  118. {
  119. myHp = 0;
  120. fxAILogicBasic.Dispose();
  121. Dispose();
  122. }
  123. return;
  124. }
  125. else
  126. {
  127. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  128. TriggerHero(collision, heroEntityMono);
  129. }
  130. }
  131. protected void TriggerHero(Collider collision, HeroEntityMono heroEntityMono)
  132. {
  133. if (heroEntityMono == null)
  134. {
  135. return;
  136. }
  137. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  138. if (target.IsEnemy == CombatHeroEntity.IsEnemy)
  139. {
  140. return;
  141. }
  142. ITimeLineTriggerEvent timeLineTriggerEvent =
  143. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  144. if (timeLineTriggerEvent != null)
  145. {
  146. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  147. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  148. if (!string.IsNullOrEmpty(hitFxName))
  149. {
  150. FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName);
  151. }
  152. AudioManager.Instance.PlayAudio(hitAudioName, false);
  153. if (!isPenetrate)
  154. {
  155. Dispose();
  156. }
  157. }
  158. }
  159. private void FinishHit(Vector3 pos, string hitFxName)
  160. {
  161. if (!string.IsNullOrEmpty(hitFxName))
  162. {
  163. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  164. pos, null, false, null, null);
  165. }
  166. }
  167. protected override void ProCombatUpdate(float time)
  168. {
  169. currTime += _addTime * time;
  170. dirLerpTime += time * 4F;
  171. if (dirLerpTime > 1)
  172. {
  173. dirLerpTime = 1;
  174. }
  175. GetTargetPos();
  176. Vector3 dir = (endPos - _currPos).normalized;
  177. dir = Vector3.Lerp(startDir, dir, dirLerpTime).normalized;
  178. // startDir= dir;
  179. Vector3 lasetPos = _currPos;
  180. _currPos += dir * speed * time;
  181. gameObject.transform.position = _currPos;
  182. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  183. if (Vector3.Distance(endPos, _currPos) < 0.5f)
  184. {
  185. Dispose();
  186. }
  187. }
  188. protected override void ProDispose()
  189. {
  190. if (UnRegister != null)
  191. {
  192. UnRegister.UnRegister();
  193. }
  194. UnRegister = null;
  195. }
  196. }
  197. }