BombAffector.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using UnityEngine;
  3. namespace Xft
  4. {
  5. public class BombAffector : Affector
  6. {
  7. public BombAffector(Transform obj, BOMBTYPE gtype, BOMBDECAYTYPE dtype, float mag, float decay, Vector3 axis, EffectNode node) : base(node, AFFECTORTYPE.BombAffector)
  8. {
  9. this.BombType = gtype;
  10. this.DecayType = dtype;
  11. this.Magnitude = mag;
  12. this.Decay = decay;
  13. this.BombAxis = axis;
  14. this.BombAxis.Normalize();
  15. this.BombObj = obj;
  16. }
  17. public override void Reset()
  18. {
  19. this.ElapsedTime = 0f;
  20. }
  21. public override void Update(float deltaTime)
  22. {
  23. deltaTime = 0.01666f;
  24. float num = this.Magnitude;
  25. Vector3 vector = this.BombObj.rotation * this.BombAxis;
  26. Vector3 vector2 = this.Node.GetOriginalPos() - this.BombObj.position;
  27. float num2 = vector2.magnitude;
  28. Vector3 a = Vector3.zero;
  29. if (vector2 == Vector3.zero)
  30. {
  31. }
  32. if (this.DecayType == BOMBDECAYTYPE.None || num2 <= this.Decay)
  33. {
  34. switch (this.BombType)
  35. {
  36. case BOMBTYPE.Planar:
  37. num2 = Vector3.Dot(vector, vector2);
  38. if (num2 < 0f)
  39. {
  40. num2 = -num2;
  41. a = -vector;
  42. }
  43. else
  44. {
  45. a = vector;
  46. }
  47. break;
  48. case BOMBTYPE.Spherical:
  49. a = vector2 / num2;
  50. break;
  51. case BOMBTYPE.Cylindrical:
  52. num2 = Vector3.Dot(vector, vector2);
  53. a = vector2 - num2 * vector;
  54. num2 = a.magnitude;
  55. if (num2 != 0f)
  56. {
  57. a /= num2;
  58. }
  59. break;
  60. default:
  61. UnityEngine.Debug.LogError("wrong bomb type!");
  62. break;
  63. }
  64. float num3 = 1f;
  65. if (this.DecayType == BOMBDECAYTYPE.Linear)
  66. {
  67. num3 = (this.Decay - num2) / this.Decay;
  68. }
  69. else if (this.DecayType == BOMBDECAYTYPE.Exponential)
  70. {
  71. num3 = Mathf.Exp(-num2 / this.Decay);
  72. }
  73. this.ElapsedTime += deltaTime;
  74. num /= this.ElapsedTime * this.ElapsedTime;
  75. this.Node.Velocity += num3 * num * deltaTime * a;
  76. }
  77. }
  78. protected BOMBTYPE BombType;
  79. protected BOMBDECAYTYPE DecayType;
  80. protected float Magnitude;
  81. protected float Decay;
  82. protected Vector3 BombAxis;
  83. protected Transform BombObj;
  84. protected float ElapsedTime;
  85. }
  86. }