ScaleAffector.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using UnityEngine;
  3. namespace Xft
  4. {
  5. public class ScaleAffector : Affector
  6. {
  7. public ScaleAffector(RSTYPE type, EffectNode node) : base(node, AFFECTORTYPE.ScaleAffector)
  8. {
  9. this.SType = type;
  10. }
  11. public ScaleAffector(float x, float y, EffectNode node) : base(node, AFFECTORTYPE.ScaleAffector)
  12. {
  13. this.SType = RSTYPE.SIMPLE;
  14. this.DeltaX = x;
  15. this.DeltaY = y;
  16. }
  17. public override void Reset()
  18. {
  19. this.IsFirst = true;
  20. this.Node.Scale = Vector3.one;
  21. }
  22. public override void Update(float deltaTime)
  23. {
  24. if (this.IsFirst)
  25. {
  26. if (this.SType == RSTYPE.RANDOM)
  27. {
  28. this.DeltaX = UnityEngine.Random.Range(this.Node.Owner.DeltaScaleX, this.Node.Owner.DeltaScaleXMax);
  29. this.DeltaY = UnityEngine.Random.Range(this.Node.Owner.DeltaScaleY, this.Node.Owner.DeltaScaleYMax);
  30. }
  31. else
  32. {
  33. this.DeltaX = this.Node.Owner.DeltaScaleX;
  34. this.DeltaY = this.Node.Owner.DeltaScaleY;
  35. }
  36. this.IsFirst = false;
  37. }
  38. float elapsedTime = this.Node.GetElapsedTime();
  39. if (this.SType == RSTYPE.CURVE)
  40. {
  41. if (this.Node.Owner.UseSameScaleCurve)
  42. {
  43. float num = this.Node.Owner.ScaleXCurve.Evaluate(elapsedTime);
  44. this.Node.Scale.x = num;
  45. this.Node.Scale.y = num;
  46. }
  47. else
  48. {
  49. this.Node.Scale.x = this.Node.Owner.ScaleXCurve.Evaluate(elapsedTime);
  50. this.Node.Scale.y = this.Node.Owner.ScaleYCurve.Evaluate(elapsedTime);
  51. }
  52. }
  53. else if (this.SType == RSTYPE.RANDOM)
  54. {
  55. float num2 = this.Node.Scale.x + this.DeltaX * deltaTime;
  56. float num3 = this.Node.Scale.y + this.DeltaY * deltaTime;
  57. if (num2 > 0f)
  58. {
  59. this.Node.Scale.x = num2;
  60. }
  61. if (num3 > 0f)
  62. {
  63. this.Node.Scale.y = num3;
  64. }
  65. }
  66. else if (this.SType == RSTYPE.CURVE01)
  67. {
  68. float num4 = this.Node.Owner.ScaleCurveTime;
  69. if (num4 < 0f)
  70. {
  71. num4 = this.Node.GetLifeTime();
  72. }
  73. float num5 = elapsedTime / num4;
  74. if (num5 > 1f)
  75. {
  76. if (this.Node.Owner.ScaleWrapMode == WRAP_TYPE.CLAMP)
  77. {
  78. num5 = 1f;
  79. }
  80. else if (this.Node.Owner.ScaleWrapMode == WRAP_TYPE.LOOP)
  81. {
  82. int num6 = Mathf.FloorToInt(num5);
  83. num5 -= (float)num6;
  84. }
  85. else
  86. {
  87. int num7 = Mathf.CeilToInt(num5);
  88. int num8 = Mathf.FloorToInt(num5);
  89. if (num7 % 2 == 0)
  90. {
  91. num5 = (float)num7 - num5;
  92. }
  93. else
  94. {
  95. num5 -= (float)num8;
  96. }
  97. }
  98. }
  99. if (this.Node.Owner.UseSameScaleCurve)
  100. {
  101. float num9 = this.Node.Owner.ScaleXCurveNew.Evaluate(num5);
  102. num9 *= this.Node.Owner.MaxScaleCalue;
  103. this.Node.Scale.x = num9;
  104. this.Node.Scale.y = num9;
  105. }
  106. else
  107. {
  108. this.Node.Scale.x = this.Node.Owner.ScaleXCurveNew.Evaluate(num5) * this.Node.Owner.MaxScaleCalue;
  109. this.Node.Scale.y = this.Node.Owner.ScaleYCurveNew.Evaluate(num5) * this.Node.Owner.MaxScaleValueY;
  110. }
  111. }
  112. else if (this.SType == RSTYPE.SIMPLE)
  113. {
  114. float num10 = this.Node.Scale.x + this.DeltaX * deltaTime;
  115. float num11 = this.Node.Scale.y + this.DeltaY * deltaTime;
  116. if (num10 * this.Node.Scale.x > 0f)
  117. {
  118. this.Node.Scale.x = num10;
  119. }
  120. if (num11 * this.Node.Scale.y > 0f)
  121. {
  122. this.Node.Scale.y = num11;
  123. }
  124. }
  125. }
  126. protected RSTYPE SType;
  127. protected float DeltaX;
  128. protected float DeltaY;
  129. protected bool IsFirst = true;
  130. }
  131. }