TornadoFan.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using Sirenix.OdinInspector;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TornadoFan : AttackTrigger
  5. {
  6. [Space(30)]
  7. [Title("TornadoFan属性")]
  8. [LabelText("相对主角距离")] public float offset;
  9. [LabelText("相对于轴心旋转范围")] public Vector2 rotationRangeX;
  10. [LabelText("Y轴差值范围")] public Vector2 rotationRangeY;
  11. [LabelText("重新判定距离")] public float distance;
  12. [LabelText("落地伤害倍率")] public float landingDamageRate;
  13. [LabelText("结束击飞力的斜率")] public float forceRate;
  14. [LabelText("结束击飞力最大值")] public float forceMax;
  15. [LabelText("结束击飞力最小值")] public float forceMin;
  16. [LabelText("落地后眩晕时间")] public float weakTime;
  17. [LabelText("最大速度")]public float lerpValueMax;
  18. [LabelText("最小速度")]public float lerpValueMin;
  19. [LabelText("速度斜率")]public float lerpRate;
  20. [DisplayOnly] public int damage;
  21. [DisplayOnly] public float totalTime;
  22. [DisplayOnly] public float time; //经过的时间
  23. public List<Vector3> targetPoss;
  24. public override void Update()
  25. {
  26. base.Update();
  27. time += Time.deltaTime;
  28. if (time >= totalTime)
  29. {
  30. for (int i = 0; i < trigedObjs.Count; i++)
  31. {
  32. BeHitTrigger beHitTrigger = trigedObjs[i];
  33. MoveCharacter moveCharacter = beHitTrigger.owner as MoveCharacter;
  34. if (moveCharacter != null)
  35. {
  36. AttackController.AttackMethod attackMethod = new AttackController.AttackMethod();
  37. attackMethod.attackInfo = new AttackInfo();
  38. attackMethod.attackInfo.attackEffect = new List<AttackEffect>();
  39. attackMethod.attackInfo.attackEffect.Add(AttackEffect.BlowUp);
  40. AttackInfo.BlowUp blowUp = attackMethod.attackInfo.blowUp;
  41. float dir = moveCharacter.transform.position.x - transform.position.x;
  42. if (dir >= 0)
  43. {
  44. blowUp.dir = new Vector3(1, 0.5f, 0);
  45. blowUp.force = -forceRate * dir + forceMax;
  46. }
  47. else
  48. {
  49. blowUp.dir = new Vector3(-1, 0.5f, 0);
  50. blowUp.force = forceRate * dir + forceMax;
  51. }
  52. if(blowUp.force >= 0)
  53. {
  54. blowUp.time = weakTime;
  55. blowUp.haveLandingDamage = true;
  56. blowUp.landingDamageRate = landingDamageRate;
  57. attackMethod.attackInfo.blowUp = blowUp;
  58. moveCharacter.attributeStatus.AddBlowUp(attackMethod, owner.bodyTrans);
  59. moveCharacter.bodyCollider.layer = LayerMask.NameToLayer("BodyToPlatformCollider");
  60. moveCharacter.attributeStatus.landingDamageFrom = owner;
  61. }
  62. else
  63. {
  64. moveCharacter.ChangeState(CharacterState.Idle);
  65. bool canfly = moveCharacter.canFly;
  66. moveCharacter.rb.useGravity = !canfly;
  67. moveCharacter.nowCanFly = canfly;
  68. }
  69. }
  70. }
  71. gameObject.SetActive(false);
  72. return;
  73. }
  74. int targetLen = targetPoss.Count;
  75. int trigedLen = trigedObjs.Count;
  76. if (targetLen < trigedLen)
  77. {
  78. for (int i = 0; i < trigedLen - targetLen; i++)
  79. {
  80. targetPoss.Add(CalculateTargetPos(trigedObjs[targetLen + i].owner.transform.position));
  81. }
  82. }
  83. else if (targetLen > trigedLen)
  84. {
  85. for (int i = 0; i < targetLen - trigedLen; i++)
  86. {
  87. targetPoss.RemoveAt(0);
  88. }
  89. }
  90. for (int i = 0; i < targetPoss.Count; i++)
  91. //for (int i = 0; i < trigedObjs.Count; i++)
  92. {
  93. BeHitTrigger beHitTrigger = trigedObjs[i];
  94. MoveCharacter moveCharacter = beHitTrigger.owner as MoveCharacter;
  95. if (moveCharacter != null)
  96. {
  97. if (moveCharacter.state != CharacterState.Another && moveCharacter.state != CharacterState.Die)
  98. {
  99. moveCharacter.ChangeState(CharacterState.Another);
  100. moveCharacter.ani.Play(AnimatorHash.ANIMATOR_weak, 0, 0);
  101. if (moveCharacter.nowCanFly == false)
  102. {
  103. moveCharacter.rb.useGravity = false;
  104. moveCharacter.nowCanFly = true;
  105. }
  106. }
  107. Vector3 nowPos = moveCharacter.transform.position;
  108. Vector3 targetPos = nowPos;
  109. targetPos.x = transform.position.x;
  110. float targetDistance = Vector3.Distance(nowPos, targetPoss[i]);
  111. if (targetDistance < distance)
  112. {
  113. targetPoss[i] = CalculateTargetPos(nowPos);
  114. }
  115. float lerpValue = lerpValueMax - (targetDistance * lerpRate);
  116. if(lerpValue < lerpValueMin)
  117. {
  118. lerpValue = lerpValueMin;
  119. }
  120. //moveCharacter.transform.position = Vector3.Lerp(nowPos, targetPoss[i], lerpValue * Time.deltaTime);
  121. moveCharacter.rb.velocity = (targetPoss[i] - nowPos).normalized * lerpValue;
  122. //moveCharacter.transform.position = Vector3.Lerp(nowPos, targetPos, lerpValue * Time.deltaTime);
  123. }
  124. }
  125. }
  126. public void Init()
  127. {
  128. float dir = owner.bodyTrans.localScale.x;
  129. Vector3 targetPos = owner.transform.position;
  130. if (dir > 0)
  131. {
  132. targetPos -= new Vector3(offset,0,0);
  133. }
  134. else
  135. {
  136. targetPos += new Vector3(offset, 0, 0);
  137. }
  138. targetPos.y = 0;
  139. attackMethod.attackInfo.damage = damage;
  140. transform.position = targetPos;
  141. targetPoss = new List<Vector3>();
  142. time = 0;
  143. gameObject.SetActive(true);
  144. }
  145. public Vector3 CalculateTargetPos(Vector3 originalPos)
  146. {
  147. float dir = originalPos.x < transform.position.x ? 1 : -1;
  148. Vector3 targetPos = transform.position;
  149. targetPos.x += dir * Random.Range(rotationRangeX.x,rotationRangeX.y);
  150. Vector2 rangeY = new Vector2(originalPos.y + rotationRangeY.x, originalPos.y + rotationRangeY.y);
  151. if(rangeY.x < 0)
  152. {
  153. rangeY.x = 0;
  154. }
  155. targetPos.y = Random.Range(rangeY.x, rangeY.y);
  156. return targetPos;
  157. }
  158. }