TornadoFan.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 weakTime;
  16. public float lerpValue;
  17. [DisplayOnly] public int damage;
  18. [DisplayOnly] public float totalTime;
  19. [DisplayOnly] public float time; //经过的时间
  20. public List<Vector3> targetPoss;
  21. public override void Update()
  22. {
  23. base.Update();
  24. time += Time.deltaTime;
  25. if (time >= totalTime)
  26. {
  27. for (int i = 0; i < trigedObjs.Count; i++)
  28. {
  29. BeHitTrigger beHitTrigger = trigedObjs[i];
  30. MoveCharacter moveCharacter = beHitTrigger.owner as MoveCharacter;
  31. if (moveCharacter != null)
  32. {
  33. AttackController.AttackMethod attackMethod = new AttackController.AttackMethod();
  34. attackMethod.attackInfo = new AttackInfo();
  35. attackMethod.attackInfo.attackEffect = new List<AttackEffect>();
  36. attackMethod.attackInfo.attackEffect.Add(AttackEffect.BlowUp);
  37. AttackInfo.BlowUp blowUp = attackMethod.attackInfo.blowUp;
  38. float dir = moveCharacter.transform.position.x - transform.position.x;
  39. if (dir >= 0)
  40. {
  41. blowUp.dir = new Vector3(1, 0.5f, 0);
  42. blowUp.force = -forceRate * dir + forceMax;
  43. }
  44. else
  45. {
  46. blowUp.dir = new Vector3(-1, 0.5f, 0);
  47. blowUp.force = forceRate * dir + forceMax;
  48. }
  49. blowUp.time = weakTime;
  50. blowUp.haveLandingDamage = true;
  51. blowUp.landingDamageRate = landingDamageRate;
  52. attackMethod.attackInfo.blowUp = blowUp;
  53. moveCharacter.attributeStatus.AddBlowUp(attackMethod, owner.bodyTrans);
  54. moveCharacter.bodyCollider.layer = LayerMask.NameToLayer("BodyToPlatformCollider");
  55. moveCharacter.attributeStatus.landingDamageFrom = owner;
  56. }
  57. }
  58. gameObject.SetActive(false);
  59. return;
  60. }
  61. int targetLen = targetPoss.Count;
  62. int trigedLen = trigedObjs.Count;
  63. if (targetLen < trigedLen)
  64. {
  65. for (int i = 0; i < trigedLen - targetLen; i++)
  66. {
  67. targetPoss.Add(CalculateTargetPos(trigedObjs[targetLen + i].owner.transform.position));
  68. }
  69. }
  70. else if (targetLen > trigedLen)
  71. {
  72. for (int i = 0; i < targetLen - trigedLen; i++)
  73. {
  74. targetPoss.RemoveAt(0);
  75. }
  76. }
  77. for (int i = 0; i < targetPoss.Count; i++)
  78. //for (int i = 0; i < trigedObjs.Count; i++)
  79. {
  80. BeHitTrigger beHitTrigger = trigedObjs[i];
  81. MoveCharacter moveCharacter = beHitTrigger.owner as MoveCharacter;
  82. if (moveCharacter != null)
  83. {
  84. if (moveCharacter.state != CharacterState.Another && moveCharacter.state != CharacterState.Die)
  85. {
  86. moveCharacter.ChangeState(CharacterState.Another);
  87. moveCharacter.ani.Play(AnimatorHash.ANIMATOR_weak, 0, 0);
  88. if (moveCharacter.nowCanFly == false)
  89. {
  90. moveCharacter.rb.useGravity = false;
  91. moveCharacter.nowCanFly = true;
  92. }
  93. }
  94. Vector3 nowPos = moveCharacter.transform.position;
  95. Vector3 targetPos = nowPos;
  96. targetPos.x = transform.position.x;
  97. if (Vector3.Distance(nowPos, targetPoss[i]) < distance)
  98. {
  99. targetPoss[i] = CalculateTargetPos(nowPos);
  100. }
  101. moveCharacter.transform.position = Vector3.Lerp(nowPos, targetPoss[i], lerpValue * Time.deltaTime);
  102. //moveCharacter.transform.position = Vector3.Lerp(nowPos, targetPos, lerpValue * Time.deltaTime);
  103. }
  104. }
  105. }
  106. public void Init()
  107. {
  108. float dir = owner.bodyTrans.localScale.x;
  109. Vector3 targetPos = owner.transform.position;
  110. if (dir > 0)
  111. {
  112. targetPos -= new Vector3(offset,0,0);
  113. }
  114. else
  115. {
  116. targetPos += new Vector3(offset, 0, 0);
  117. }
  118. targetPos.y = 0;
  119. attackMethod.attackInfo.damage = damage;
  120. transform.position = targetPos;
  121. targetPoss = new List<Vector3>();
  122. }
  123. public Vector3 CalculateTargetPos(Vector3 originalPos)
  124. {
  125. float dir = originalPos.x < transform.position.x ? 1 : -1;
  126. Vector3 targetPos = transform.position;
  127. targetPos.x += dir * Random.Range(rotationRangeX.x,rotationRangeX.y);
  128. Vector2 rangeY = new Vector2(originalPos.y + rotationRangeY.x, originalPos.y + rotationRangeY.y);
  129. if(rangeY.x < 0)
  130. {
  131. rangeY.x = 0;
  132. }
  133. targetPos.y = Random.Range(rangeY.x, rangeY.y);
  134. return targetPos;
  135. }
  136. }