SineAffector.cs 759 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using UnityEngine;
  3. namespace Xft
  4. {
  5. public class SineAffector : Affector
  6. {
  7. public SineAffector(EffectNode node) : base(node, AFFECTORTYPE.SineAffector)
  8. {
  9. }
  10. public override void Update(float deltaTime)
  11. {
  12. float sineTime = this.Node.Owner.SineTime;
  13. float d = this.Node.Owner.SineMagnitude;
  14. if (this.Node.Owner.SineMagType != MAGTYPE.Fixed)
  15. {
  16. d = this.Node.Owner.SineMagCurveX.Evaluate(this.Node.GetElapsedTime());
  17. }
  18. float f = this.Node.GetElapsedTime() / sineTime * 2f * 3.14159274f;
  19. Vector3 b = Mathf.Sin(f) * this.Node.Owner.SineForce * d;
  20. if (this.Node.Owner.SineIsAccelarate)
  21. {
  22. this.Node.Velocity += b;
  23. }
  24. else
  25. {
  26. this.Node.Position += b;
  27. }
  28. }
  29. }
  30. }