MegaSinusCurveWarp.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. [AddComponentMenu("Modifiers/Warps/Sinus Curve")]
  3. public class MegaSinusCurveWarp : MegaWarp
  4. {
  5. public float scale = 1.0f;
  6. public float wave = 1.0f;
  7. public float speed = 1.0f;
  8. public float phase = 0.0f;
  9. public bool animate = false;
  10. Matrix4x4 mat = new Matrix4x4();
  11. public override string WarpName() { return "Sinus Curve"; }
  12. public override string GetHelpURL() { return "Bubble.htm"; }
  13. public override Vector3 Map(int i, Vector3 p)
  14. {
  15. p = tm.MultiplyPoint3x4(p);
  16. Vector3 ip = p;
  17. float dist = p.magnitude;
  18. float dcy = Mathf.Exp(-totaldecay * Mathf.Abs(dist));
  19. p.y += Mathf.Sin(phase + (p.x * wave) + p.y + p.z) * scale;
  20. p = Vector3.Lerp(ip, p, dcy);
  21. return invtm.MultiplyPoint3x4(p);
  22. }
  23. void Update()
  24. {
  25. if ( animate )
  26. {
  27. if ( Application.isPlaying )
  28. phase += Time.deltaTime * speed;
  29. }
  30. Prepare(Decay);
  31. }
  32. public override bool Prepare(float decay)
  33. {
  34. totaldecay = Decay + decay;
  35. if ( totaldecay < 0.0f )
  36. totaldecay = 0.0f;
  37. tm = transform.worldToLocalMatrix;
  38. invtm = tm.inverse;
  39. mat = Matrix4x4.identity;
  40. SetAxis(mat);
  41. return true;
  42. }
  43. }