ParticleForceFieldsDemo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using MirzaBeig.Scripting.Effects;
  7. public class ParticleForceFieldsDemo : MonoBehaviour
  8. {
  9. [Header("Overview")]
  10. public Text FPSText;
  11. public Text particleCountText;
  12. public Toggle postProcessingToggle;
  13. public MonoBehaviour postProcessing;
  14. [Header("Particle System Settings")]
  15. new public ParticleSystem particleSystem;
  16. ParticleSystem.MainModule particleSystemMainModule;
  17. ParticleSystem.EmissionModule particleSystemEmissionModule;
  18. public Text maxParticlesText;
  19. public Text particlesPerSecondText;
  20. public Slider maxParticlesSlider;
  21. public Slider particlesPerSecondSlider;
  22. [Header("Attraction Particle Force Field Settings")]
  23. public AttractionParticleForceField attractionParticleForceField;
  24. public Text attractionParticleForceFieldRadiusText;
  25. public Text attractionParticleForceFieldMaxForceText;
  26. public Text attractionParticleForceFieldArrivalRadiusText;
  27. public Text attractionParticleForceFieldArrivedRadiusText;
  28. public Text attractionParticleForceFieldPositionTextX;
  29. public Text attractionParticleForceFieldPositionTextY;
  30. public Text attractionParticleForceFieldPositionTextZ;
  31. public Slider attractionParticleForceFieldRadiusSlider;
  32. public Slider attractionParticleForceFieldMaxForceSlider;
  33. public Slider attractionParticleForceFieldArrivalRadiusSlider;
  34. public Slider attractionParticleForceFieldArrivedRadiusSlider;
  35. public Slider attractionParticleForceFieldPositionSliderX;
  36. public Slider attractionParticleForceFieldPositionSliderY;
  37. public Slider attractionParticleForceFieldPositionSliderZ;
  38. [Header("Vortex Particle Force Field Settings")]
  39. public VortexParticleForceField vortexParticleForceField;
  40. public Text vortexParticleForceFieldRadiusText;
  41. public Text vortexParticleForceFieldMaxForceText;
  42. public Text vortexParticleForceFieldRotationTextX;
  43. public Text vortexParticleForceFieldRotationTextY;
  44. public Text vortexParticleForceFieldRotationTextZ;
  45. public Text vortexParticleForceFieldPositionTextX;
  46. public Text vortexParticleForceFieldPositionTextY;
  47. public Text vortexParticleForceFieldPositionTextZ;
  48. public Slider vortexParticleForceFieldRadiusSlider;
  49. public Slider vortexParticleForceFieldMaxForceSlider;
  50. public Slider vortexParticleForceFieldRotationSliderX;
  51. public Slider vortexParticleForceFieldRotationSliderY;
  52. public Slider vortexParticleForceFieldRotationSliderZ;
  53. public Slider vortexParticleForceFieldPositionSliderX;
  54. public Slider vortexParticleForceFieldPositionSliderY;
  55. public Slider vortexParticleForceFieldPositionSliderZ;
  56. void Start()
  57. {
  58. // Overview.
  59. if (postProcessing)
  60. {
  61. postProcessingToggle.isOn = postProcessing.enabled;
  62. }
  63. // Particle system settings.
  64. particleSystemMainModule = particleSystem.main;
  65. particleSystemEmissionModule = particleSystem.emission;
  66. maxParticlesSlider.value = particleSystemMainModule.maxParticles;
  67. particlesPerSecondSlider.value = particleSystemEmissionModule.rateOverTime.constant;
  68. maxParticlesText.text = "Max Particles: " + maxParticlesSlider.value;
  69. particlesPerSecondText.text = "Particles Per Second: " + particlesPerSecondSlider.value;
  70. // Attraction particle force field settings.
  71. attractionParticleForceFieldRadiusSlider.value = attractionParticleForceField.radius;
  72. attractionParticleForceFieldMaxForceSlider.value = attractionParticleForceField.force;
  73. attractionParticleForceFieldArrivalRadiusSlider.value = attractionParticleForceField.arrivalRadius;
  74. attractionParticleForceFieldArrivedRadiusSlider.value = attractionParticleForceField.arrivedRadius;
  75. Vector3 attractionParticleForceFieldPosition = attractionParticleForceField.transform.position;
  76. attractionParticleForceFieldPositionSliderX.value = attractionParticleForceFieldPosition.x;
  77. attractionParticleForceFieldPositionSliderY.value = attractionParticleForceFieldPosition.y;
  78. attractionParticleForceFieldPositionSliderZ.value = attractionParticleForceFieldPosition.z;
  79. attractionParticleForceFieldRadiusText.text = "Radius: " + attractionParticleForceFieldRadiusSlider.value;
  80. attractionParticleForceFieldMaxForceText.text = "Max Force: " + attractionParticleForceFieldMaxForceSlider.value;
  81. attractionParticleForceFieldArrivalRadiusText.text = "Arrival Radius: " + attractionParticleForceFieldArrivalRadiusSlider.value;
  82. attractionParticleForceFieldArrivedRadiusText.text = "Arrived Radius: " + attractionParticleForceFieldArrivedRadiusSlider.value;
  83. attractionParticleForceFieldPositionTextX.text = "Position X: " + attractionParticleForceFieldPositionSliderX.value;
  84. attractionParticleForceFieldPositionTextY.text = "Position Y: " + attractionParticleForceFieldPositionSliderY.value;
  85. attractionParticleForceFieldPositionTextZ.text = "Position Z: " + attractionParticleForceFieldPositionSliderZ.value;
  86. // Vortex particle force field settings.
  87. vortexParticleForceFieldRadiusSlider.value = vortexParticleForceField.radius;
  88. vortexParticleForceFieldMaxForceSlider.value = vortexParticleForceField.force;
  89. Vector3 vortexParticleForceFieldRotation = vortexParticleForceField.transform.eulerAngles;
  90. vortexParticleForceFieldRotationSliderX.value = vortexParticleForceFieldRotation.x;
  91. vortexParticleForceFieldRotationSliderY.value = vortexParticleForceFieldRotation.y;
  92. vortexParticleForceFieldRotationSliderZ.value = vortexParticleForceFieldRotation.z;
  93. Vector3 vortexParticleForceFieldPosition = vortexParticleForceField.transform.position;
  94. vortexParticleForceFieldPositionSliderX.value = vortexParticleForceFieldPosition.x;
  95. vortexParticleForceFieldPositionSliderY.value = vortexParticleForceFieldPosition.y;
  96. vortexParticleForceFieldPositionSliderZ.value = vortexParticleForceFieldPosition.z;
  97. vortexParticleForceFieldRadiusText.text = "Radius: " + vortexParticleForceFieldRadiusSlider.value;
  98. vortexParticleForceFieldMaxForceText.text = "Max Force: " + vortexParticleForceFieldMaxForceSlider.value;
  99. vortexParticleForceFieldRotationTextX.text = "Rotation X: " + vortexParticleForceFieldRotationSliderX.value;
  100. vortexParticleForceFieldRotationTextY.text = "Rotation Y: " + vortexParticleForceFieldRotationSliderY.value;
  101. vortexParticleForceFieldRotationTextZ.text = "Rotation Z: " + vortexParticleForceFieldRotationSliderZ.value;
  102. vortexParticleForceFieldPositionTextX.text = "Position X: " + vortexParticleForceFieldPositionSliderX.value;
  103. vortexParticleForceFieldPositionTextY.text = "Position Y: " + vortexParticleForceFieldPositionSliderY.value;
  104. vortexParticleForceFieldPositionTextZ.text = "Position Z: " + vortexParticleForceFieldPositionSliderZ.value;
  105. }
  106. void Update()
  107. {
  108. // Overview.
  109. FPSText.text = "FPS: " + 1.0f / Time.deltaTime;
  110. particleCountText.text = "Particle Count: " + particleSystem.particleCount;
  111. }
  112. public void ReloadScene()
  113. {
  114. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  115. }
  116. // Particle system settings.
  117. public void SetMaxParticles(float value)
  118. {
  119. particleSystemMainModule.maxParticles = (int)value;
  120. maxParticlesText.text = "Max Particles: " + value;
  121. }
  122. public void SetParticleEmissionPerSecond(float value)
  123. {
  124. particleSystemEmissionModule.rateOverTime = value;
  125. particlesPerSecondText.text = "Particles Per Second: " + value;
  126. }
  127. // Attraction particle force field settings.
  128. public void SetAttractionParticleForceFieldRadius(float value)
  129. {
  130. attractionParticleForceField.radius = value;
  131. attractionParticleForceFieldRadiusText.text = "Radius: " + value;
  132. }
  133. public void SetAttractionParticleForceFieldMaxForce(float value)
  134. {
  135. attractionParticleForceField.force = value;
  136. attractionParticleForceFieldMaxForceText.text = "Max Force: " + value;
  137. }
  138. public void SetAttractionParticleForceFieldArrivalRadius(float value)
  139. {
  140. attractionParticleForceField.arrivalRadius = value;
  141. attractionParticleForceFieldArrivalRadiusText.text = "Arrival Radius: " + value;
  142. }
  143. public void SetAttractionParticleForceFieldArrivedRadius(float value)
  144. {
  145. attractionParticleForceField.arrivedRadius = value;
  146. attractionParticleForceFieldArrivedRadiusText.text = "Arrived Radius: " + value;
  147. }
  148. public void SetAttractionParticleForceFieldPositionX(float value)
  149. {
  150. Vector3 position = attractionParticleForceField.transform.position;
  151. position.x = value;
  152. attractionParticleForceField.transform.position = position;
  153. attractionParticleForceFieldPositionTextX.text = "Position X: " + value;
  154. }
  155. public void SetAttractionParticleForceFieldPositionY(float value)
  156. {
  157. Vector3 position = attractionParticleForceField.transform.position;
  158. position.y = value;
  159. attractionParticleForceField.transform.position = position;
  160. attractionParticleForceFieldPositionTextY.text = "Position Y: " + value;
  161. }
  162. public void SetAttractionParticleForceFieldPositionZ(float value)
  163. {
  164. Vector3 position = attractionParticleForceField.transform.position;
  165. position.z = value;
  166. attractionParticleForceField.transform.position = position;
  167. attractionParticleForceFieldPositionTextZ.text = "Position Z: " + value;
  168. }
  169. // Vortex particle force field settings.
  170. public void SetVortexParticleForceFieldRadius(float value)
  171. {
  172. vortexParticleForceField.radius = value;
  173. vortexParticleForceFieldRadiusText.text = "Radius: " + value;
  174. }
  175. public void SetVortexParticleForceFieldMaxForce(float value)
  176. {
  177. vortexParticleForceField.force = value;
  178. vortexParticleForceFieldMaxForceText.text = "Max Force: " + value;
  179. }
  180. public void SetVortexParticleForceFieldRotationX(float value)
  181. {
  182. Vector3 rotation = vortexParticleForceField.transform.eulerAngles;
  183. rotation.x = value;
  184. vortexParticleForceField.transform.eulerAngles = rotation;
  185. vortexParticleForceFieldRotationTextX.text = "Rotation X: " + value;
  186. }
  187. public void SetVortexParticleForceFieldRotationY(float value)
  188. {
  189. Vector3 rotation = vortexParticleForceField.transform.eulerAngles;
  190. rotation.y = value;
  191. vortexParticleForceField.transform.eulerAngles = rotation;
  192. vortexParticleForceFieldRotationTextY.text = "Rotation Y: " + value;
  193. }
  194. public void SetVortexParticleForceFieldRotationZ(float value)
  195. {
  196. Vector3 rotation = vortexParticleForceField.transform.eulerAngles;
  197. rotation.z = value;
  198. vortexParticleForceField.transform.eulerAngles = rotation;
  199. vortexParticleForceFieldRotationTextZ.text = "Rotation Z: " + value;
  200. }
  201. public void SetVortexParticleForceFieldPositionX(float value)
  202. {
  203. Vector3 position = vortexParticleForceField.transform.position;
  204. position.x = value;
  205. vortexParticleForceField.transform.position = position;
  206. vortexParticleForceFieldPositionTextX.text = "Position X: " + value;
  207. }
  208. public void SetVortexParticleForceFieldPositionY(float value)
  209. {
  210. Vector3 position = vortexParticleForceField.transform.position;
  211. position.y = value;
  212. vortexParticleForceField.transform.position = position;
  213. vortexParticleForceFieldPositionTextY.text = "Position Y: " + value;
  214. }
  215. public void SetVortexParticleForceFieldPositionZ(float value)
  216. {
  217. Vector3 position = vortexParticleForceField.transform.position;
  218. position.z = value;
  219. vortexParticleForceField.transform.position = position;
  220. vortexParticleForceFieldPositionTextZ.text = "Position Z: " + value;
  221. }
  222. }