ParticlePlaybackExtensions.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 
  2. // =================================
  3. // Namespaces.
  4. // =================================
  5. using UnityEngine;
  6. using UnityEditor;
  7. using System.Collections;
  8. // =================================
  9. // Define namespace.
  10. // =================================
  11. namespace MirzaBeig
  12. {
  13. namespace EditorExtensions
  14. {
  15. namespace Utilities
  16. {
  17. // =================================
  18. // Classes.
  19. // =================================
  20. public static class ParticlePlaybackExtensions
  21. {
  22. // =================================
  23. // Nested classes and structures.
  24. // =================================
  25. // ...
  26. // =================================
  27. // Variables.
  28. // =================================
  29. // ...
  30. // =================================
  31. // Functions.
  32. // =================================
  33. // Stops the system, then re-simulates to same playback time before stop.
  34. // Note that time has a range of 0.0f to the duration set in the ParticleSystem component.
  35. // It will restart when it hits duration automatically, and I can't think of an easy way
  36. // around that. So for systems that don't loop, this may cause problems with some particles
  37. // not being emitted when scrubbing through, even though this method allows for continuous
  38. // playback since it resumes from the last position.
  39. // In addition, you'll also notice jumps every n-seconds, where n is the duration.
  40. // Since the internal emitter time is reset... so it's kinda-sorta SUPER annoying.
  41. public static void restartToCurrentTime(this ParticleSystem particleSystem)
  42. {
  43. // Save time.
  44. float time = particleSystem.time;
  45. // Restart (without actually setting restart to true in last Simulate() parameter).
  46. particleSystem.Stop(false);
  47. particleSystem.Clear(false);
  48. particleSystem.Play(false);
  49. particleSystem.Simulate(time, false, false);
  50. }
  51. // Stops the system, then re-simulates to given time.
  52. public static void setPlaybackPosition(this ParticleSystem particleSystem, float time)
  53. {
  54. particleSystem.Stop(false);
  55. particleSystem.Clear(false);
  56. particleSystem.Play(false);
  57. particleSystem.Simulate(time, false, false);
  58. }
  59. // =================================
  60. // End functions.
  61. // =================================
  62. }
  63. // =================================
  64. // End namespace.
  65. // =================================
  66. }
  67. }
  68. }
  69. // =================================
  70. // --END-- //
  71. // =================================