VibrationParameters.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. public class VibrationParameters : MonoBehaviour
  6. {
  7. public TMP_InputField input_Amplitude;
  8. public TMP_InputField input_Frequency;
  9. public TMP_InputField input_Time;
  10. private float amplitude;
  11. private float frequency;
  12. private float time;
  13. private const float min = 0f;
  14. private const float max = 1f;
  15. private const float max_time = 3.1f;
  16. private void Start()
  17. {
  18. amplitude = 0.5f;
  19. frequency = 0.5f;
  20. time = 0.5f;
  21. input_Amplitude.text = amplitude.ToString();
  22. input_Frequency.text = frequency.ToString();
  23. input_Time.text = time.ToString();
  24. }
  25. #region[Amplitude]
  26. public void Plus_Amplitude()
  27. {
  28. if (amplitude < max)
  29. {
  30. amplitude += 0.01f;
  31. amplitude = float.Parse(amplitude.ToString("#0.00"));
  32. input_Amplitude.text = amplitude.ToString();
  33. }
  34. }
  35. public void Plus5_Amplitude()
  36. {
  37. if (amplitude < max)
  38. {
  39. float temp = amplitude + 0.05f;
  40. temp = float.Parse(temp.ToString("#0.00"));
  41. if (temp >= max)
  42. {
  43. amplitude = max;
  44. }
  45. else
  46. {
  47. amplitude = temp;
  48. }
  49. input_Amplitude.text = amplitude.ToString();
  50. }
  51. }
  52. public void Minus_Amplitude()
  53. {
  54. if (amplitude > min)
  55. {
  56. amplitude -= 0.10f;
  57. amplitude = float.Parse(amplitude.ToString("#0.00"));
  58. input_Amplitude.text = amplitude.ToString();
  59. }
  60. }
  61. public void Minus5_Amplitude()
  62. {
  63. if (amplitude > min)
  64. {
  65. float temp = amplitude - 0.05f;
  66. temp = float.Parse(temp.ToString("#0.00"));
  67. if (temp <= min)
  68. {
  69. amplitude = min;
  70. }
  71. else
  72. {
  73. amplitude = temp;
  74. }
  75. input_Amplitude.text = amplitude.ToString();
  76. }
  77. }
  78. #endregion
  79. #region[Frequency]
  80. public void Plus_Frequency()
  81. {
  82. if (frequency < max)
  83. {
  84. frequency += 0.01f;
  85. frequency = float.Parse(frequency.ToString("#0.00"));
  86. input_Frequency.text = frequency.ToString();
  87. }
  88. }
  89. public void Plus5_Frequency()
  90. {
  91. if (frequency < max)
  92. {
  93. float temp = frequency + 0.05f;
  94. temp = float.Parse(temp.ToString("#0.00"));
  95. if (temp >= max)
  96. {
  97. frequency = max;
  98. }
  99. else
  100. {
  101. frequency = temp;
  102. }
  103. input_Frequency.text = frequency.ToString();
  104. }
  105. }
  106. public void Minus_Frequency()
  107. {
  108. if (frequency > min)
  109. {
  110. frequency -= 0.01f;
  111. frequency = float.Parse(frequency.ToString("#0.00"));
  112. input_Frequency.text = frequency.ToString();
  113. }
  114. }
  115. public void Minus5_Frequency()
  116. {
  117. if (frequency > min)
  118. {
  119. float temp = frequency - 0.05f;
  120. temp = float.Parse(temp.ToString("#0.00"));
  121. if (temp <= min)
  122. {
  123. frequency = min;
  124. }
  125. else
  126. {
  127. frequency = temp;
  128. }
  129. input_Frequency.text = frequency.ToString();
  130. }
  131. }
  132. #endregion
  133. #region[Time]
  134. public void Plus_Time()
  135. {
  136. if (time < max_time)
  137. {
  138. time += 0.01f;
  139. time = float.Parse(time.ToString("#0.00"));
  140. input_Time.text = time.ToString();
  141. }
  142. }
  143. public void Plus5_Time()
  144. {
  145. if (time < max_time)
  146. {
  147. float temp = time + 0.05f;
  148. temp = float.Parse(temp.ToString("#0.00"));
  149. if (temp >= max_time)
  150. {
  151. time = max_time;
  152. }
  153. else
  154. {
  155. time = temp;
  156. }
  157. input_Time.text = time.ToString();
  158. }
  159. }
  160. public void Minus_Time()
  161. {
  162. if (time > min)
  163. {
  164. time -= 0.01f;
  165. time = float.Parse(time.ToString("#0.00"));
  166. input_Time.text = time.ToString();
  167. }
  168. }
  169. public void Minus5_Time()
  170. {
  171. if (time > min)
  172. {
  173. float temp = time - 0.05f;
  174. temp = float.Parse(temp.ToString("#0.00"));
  175. if (temp <= min)
  176. {
  177. time = min;
  178. }
  179. else
  180. {
  181. time = temp;
  182. }
  183. input_Time.text = time.ToString();
  184. }
  185. }
  186. #endregion
  187. }