WaveRandom.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEngine;
  3. namespace Xft
  4. {
  5. public class WaveRandom
  6. {
  7. public void Reset()
  8. {
  9. this.seeds[0] = UnityEngine.Random.Range(1f, 2f);
  10. this.seeds[1] = UnityEngine.Random.Range(1f, 2f);
  11. this.seeds[2] = UnityEngine.Random.Range(1f, 2f);
  12. this.seed = 0;
  13. }
  14. public Vector3 GetRandom(float minAmp, float maxAmp, float minRand, float maxRand, int len)
  15. {
  16. float num = maxAmp - minAmp;
  17. this.seed++;
  18. if (this.seed >= len)
  19. {
  20. this.seed = 0;
  21. }
  22. float num2 = 3.14159274f / (float)len * (float)this.seed;
  23. float num3 = 1.27323949f * num2 - 0.405284733f * num2 * num2;
  24. float num4 = minAmp + num3 * num;
  25. float num5 = 6.28318548f;
  26. for (int i = 0; i < 3; i++)
  27. {
  28. if (this.seeds[i] >= 1f)
  29. {
  30. this.seeds[i] = this.seeds[i] - 1f;
  31. this.dSeeds[i] = UnityEngine.Random.Range(minRand, maxRand);
  32. }
  33. this.seeds[i] += this.dSeeds[i];
  34. num2 = this.seeds[i] * num5;
  35. if (num2 > 3.14159274f)
  36. {
  37. num2 -= num5;
  38. }
  39. if (num2 < 0f)
  40. {
  41. num3 = 1.27323949f * num2 + 0.405284733f * num2 * num2;
  42. }
  43. else
  44. {
  45. num3 = 1.27323949f * num2 - 0.405284733f * num2 * num2;
  46. }
  47. this.disp[i] = num3 * num4;
  48. }
  49. return this.disp;
  50. }
  51. protected int seed;
  52. protected float[] dSeeds = new float[3];
  53. protected float[] seeds = new float[3];
  54. protected Vector3 disp = Vector3.zero;
  55. }
  56. }