VortexAffector.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using UnityEngine;
  3. namespace Xft
  4. {
  5. public class VortexAffector : Affector
  6. {
  7. public VortexAffector(Transform obj, Vector3 dir, bool inhRot, EffectNode node) : base(node, AFFECTORTYPE.VortexAffector)
  8. {
  9. this.Direction = dir;
  10. this.InheritRotation = inhRot;
  11. this.VortexObj = obj;
  12. if (node.Owner.IsRandomVortexDir)
  13. {
  14. this.Direction.x = UnityEngine.Random.Range(-1f, 1f);
  15. this.Direction.y = UnityEngine.Random.Range(-1f, 1f);
  16. this.Direction.z = UnityEngine.Random.Range(-1f, 1f);
  17. }
  18. this.Direction.Normalize();
  19. this.IsFirst = true;
  20. }
  21. public override void Reset()
  22. {
  23. this.IsFirst = true;
  24. this.OriginalRadius = 0f;
  25. if (this.Node.Owner.IsRandomVortexDir)
  26. {
  27. this.Direction.x = UnityEngine.Random.Range(-1f, 1f);
  28. this.Direction.y = UnityEngine.Random.Range(-1f, 1f);
  29. this.Direction.z = UnityEngine.Random.Range(-1f, 1f);
  30. }
  31. this.Direction.Normalize();
  32. }
  33. public override void Update(float deltaTime)
  34. {
  35. Vector3 vector = this.Node.GetOriginalPos() - this.VortexObj.position;
  36. if (this.Node.Owner.IsRandomVortexDir && this.IsFirst)
  37. {
  38. this.Direction = Vector3.Cross(vector, this.Direction);
  39. }
  40. Vector3 vector2 = this.Direction;
  41. if (this.InheritRotation)
  42. {
  43. vector2 = this.Node.Owner.ClientTransform.rotation * vector2;
  44. }
  45. if (this.IsFirst)
  46. {
  47. this.IsFirst = false;
  48. this.OriginalRadius = (vector - Vector3.Project(vector, vector2)).magnitude;
  49. }
  50. float sqrMagnitude = vector.sqrMagnitude;
  51. if (sqrMagnitude < 1E-06f)
  52. {
  53. return;
  54. }
  55. if (!this.Node.Owner.UseVortexMaxDistance || sqrMagnitude <= this.Node.Owner.VortexMaxDistance * this.Node.Owner.VortexMaxDistance)
  56. {
  57. float d = Vector3.Dot(vector2, vector);
  58. vector -= d * vector2;
  59. Vector3 vector3 = Vector3.zero;
  60. if (vector == Vector3.zero)
  61. {
  62. vector3 = vector;
  63. }
  64. else
  65. {
  66. vector3 = Vector3.Cross(vector2, vector).normalized;
  67. }
  68. float elapsedTime = this.Node.GetElapsedTime();
  69. float num;
  70. if (this.Node.Owner.VortexMagType == MAGTYPE.Curve_OBSOLETE)
  71. {
  72. num = this.Node.Owner.VortexCurve.Evaluate(elapsedTime);
  73. }
  74. else if (this.Node.Owner.VortexMagType == MAGTYPE.Fixed)
  75. {
  76. num = this.Node.Owner.VortexMag;
  77. }
  78. else
  79. {
  80. num = this.Node.Owner.VortexCurveX.Evaluate(elapsedTime);
  81. }
  82. if (this.Node.Owner.VortexAttenuation < 0.0001f)
  83. {
  84. vector3 *= num * deltaTime;
  85. }
  86. else
  87. {
  88. vector3 *= num * deltaTime / Mathf.Pow(Mathf.Sqrt(sqrMagnitude), this.Node.Owner.VortexAttenuation);
  89. }
  90. if (this.Node.Owner.IsVortexAccelerate)
  91. {
  92. this.Node.Velocity += vector3;
  93. }
  94. else if (this.Node.Owner.IsFixedCircle)
  95. {
  96. Vector3 vector4 = this.Node.GetOriginalPos() + vector3 - this.VortexObj.position;
  97. Vector3 b = Vector3.Project(vector4, vector2);
  98. Vector3 vector5 = vector4 - b;
  99. if (this.Node.Owner.SyncClient)
  100. {
  101. this.Node.Position = vector5.normalized * this.OriginalRadius + b;
  102. }
  103. else
  104. {
  105. this.Node.Position = this.Node.GetRealClientPos() + vector5.normalized * this.OriginalRadius + b;
  106. }
  107. }
  108. else
  109. {
  110. this.Node.Position += vector3;
  111. }
  112. }
  113. }
  114. protected Vector3 Direction;
  115. protected Transform VortexObj;
  116. protected bool InheritRotation;
  117. protected bool IsFirst = true;
  118. protected float OriginalRadius;
  119. }
  120. }