AirFieldAffector.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using UnityEngine;
  3. namespace Xft
  4. {
  5. public class AirFieldAffector : Affector
  6. {
  7. public AirFieldAffector(Transform airObj, Vector3 dir, float atten, bool useMaxdist, float maxDist, bool enableSpread, float spread, float inhV, bool inhRot, EffectNode node) : base(node, AFFECTORTYPE.AirFieldAffector)
  8. {
  9. this.AirObj = airObj;
  10. this.Direction = dir.normalized;
  11. this.Attenuation = atten;
  12. this.UseMaxDistance = useMaxdist;
  13. this.MaxDistance = maxDist;
  14. this.MaxDistanceSqr = this.MaxDistance * this.MaxDistance;
  15. this.EnableSpread = enableSpread;
  16. this.Spread = spread;
  17. this.InheritVelocity = inhV;
  18. this.InheritRotation = inhRot;
  19. this.LastFieldPos = this.AirObj.position;
  20. }
  21. public override void Reset()
  22. {
  23. this.LastFieldPos = this.AirObj.position;
  24. }
  25. public override void Update(float deltaTime)
  26. {
  27. Vector3 a;
  28. if (this.InheritRotation)
  29. {
  30. a = this.AirObj.rotation * this.Direction;
  31. }
  32. else
  33. {
  34. a = this.Direction;
  35. }
  36. Vector3 vector = Vector3.zero;
  37. vector = (this.AirObj.position - this.LastFieldPos) * this.InheritVelocity / deltaTime;
  38. this.LastFieldPos = this.AirObj.position;
  39. float d;
  40. if (this.Node.Owner.AirMagType == MAGTYPE.Fixed)
  41. {
  42. d = this.Node.Owner.AirMagnitude;
  43. }
  44. else if (this.Node.Owner.AirMagType == MAGTYPE.Curve_OBSOLETE)
  45. {
  46. d = this.Node.Owner.AirMagCurve.Evaluate(this.Node.GetElapsedTime());
  47. }
  48. else
  49. {
  50. d = this.Node.Owner.AirMagCurveX.Evaluate(this.Node.GetElapsedTime());
  51. }
  52. vector += a * d;
  53. float magnitude = vector.magnitude;
  54. float num = (!this.EnableSpread) ? 0f : Mathf.Cos(1.57079637f * this.Spread);
  55. Vector3 vector2 = this.Node.GetOriginalPos() - this.AirObj.position;
  56. float sqrMagnitude = vector2.sqrMagnitude;
  57. if (!this.UseMaxDistance || sqrMagnitude < this.MaxDistanceSqr)
  58. {
  59. Vector3 vector3 = vector;
  60. if (this.EnableSpread)
  61. {
  62. vector3 = vector2.normalized;
  63. if (Vector3.Dot(vector, vector3) < num)
  64. {
  65. return;
  66. }
  67. vector3 *= magnitude;
  68. }
  69. Vector3 vector4 = this.Node.Velocity;
  70. if (Vector3.Dot(vector3, vector4 - vector3) < 0f)
  71. {
  72. float num2 = deltaTime;
  73. if (this.UseMaxDistance && this.Attenuation > 1E-06f)
  74. {
  75. num2 *= Mathf.Pow(1f - Mathf.Sqrt(sqrMagnitude) / this.MaxDistance, this.Attenuation);
  76. }
  77. vector4 += vector3 * num2;
  78. this.Node.Velocity = vector4;
  79. }
  80. }
  81. }
  82. protected Transform AirObj;
  83. protected Vector3 Direction;
  84. protected float Attenuation;
  85. protected bool UseMaxDistance;
  86. protected float MaxDistance;
  87. protected float MaxDistanceSqr;
  88. protected bool EnableSpread;
  89. protected float Spread;
  90. protected float InheritVelocity;
  91. protected bool InheritRotation;
  92. protected Vector3 LastFieldPos;
  93. }
  94. }