MegaHump.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using UnityEngine;
  2. [AddComponentMenu("Modifiers/Hump")]
  3. public class MegaHump : MegaModifier
  4. {
  5. public float amount = 0.0f;
  6. public float cycles = 1.0f;
  7. public float phase = 0.0f;
  8. public bool animate = false;
  9. public float speed = 1.0f;
  10. public MegaAxis axis = MegaAxis.Z;
  11. float amt;
  12. Vector3 size = Vector3.zero;
  13. public override string ModName() { return "Hump"; }
  14. public override string GetHelpURL() { return "?page_id=207"; }
  15. public override Vector3 Map(int i, Vector3 p)
  16. {
  17. p = tm.MultiplyPoint3x4(p);
  18. switch ( axis )
  19. {
  20. case MegaAxis.X: p.x += amt * Mathf.Sin(Mathf.Sqrt(p.x * p.x / size.x) + Mathf.Sqrt(p.y * p.y / size.y) * Mathf.PI / 0.1f * (Mathf.Deg2Rad * cycles) + phase); break;
  21. case MegaAxis.Y: p.y += amt * Mathf.Sin(Mathf.Sqrt(p.y * p.y / size.y) + Mathf.Sqrt(p.x * p.x / size.x) * Mathf.PI / 0.1f * (Mathf.Deg2Rad * cycles) + phase); break;
  22. case MegaAxis.Z: p.z += amt * Mathf.Sin(Mathf.Sqrt(p.x * p.x / size.x) + Mathf.Sqrt(p.y * p.y / size.y) * Mathf.PI / 0.1f * (Mathf.Deg2Rad * cycles) + phase); break;
  23. }
  24. return invtm.MultiplyPoint3x4(p);
  25. }
  26. public override bool ModLateUpdate(MegaModContext mc)
  27. {
  28. if ( animate )
  29. {
  30. if ( Application.isPlaying )
  31. phase += Time.deltaTime * speed;
  32. }
  33. return Prepare(mc);
  34. }
  35. public override bool Prepare(MegaModContext mc)
  36. {
  37. size = bbox.Size();
  38. amt = amount / 100.0f;
  39. return true;
  40. }
  41. }