NonRewindableParticleSystemTimeline.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using UnityEngine;
  2. namespace Chronos
  3. {
  4. public class NonRewindableParticleSystemTimeline : ComponentTimeline<ParticleSystem>, IParticleSystemTimeline
  5. {
  6. public NonRewindableParticleSystemTimeline(Timeline timeline, ParticleSystem component) : base(timeline, component) { }
  7. private bool warnedRewind;
  8. private float _playbackSpeed;
  9. public float playbackSpeed
  10. {
  11. get { return _playbackSpeed; }
  12. set
  13. {
  14. _playbackSpeed = value;
  15. AdjustProperties();
  16. }
  17. }
  18. public float time
  19. {
  20. get { return component.time; }
  21. set { component.time = value; }
  22. }
  23. public bool enableEmission
  24. {
  25. get
  26. {
  27. return component.emission.enabled;
  28. }
  29. set
  30. {
  31. // http://forum.unity3d.com/threads/enabling-emission.364258/
  32. var emission = component.emission;
  33. emission.enabled = value;
  34. }
  35. }
  36. public bool isPlaying
  37. {
  38. get { return component.isPlaying; }
  39. }
  40. public bool isPaused
  41. {
  42. get { return component.isPaused; }
  43. }
  44. public bool isStopped
  45. {
  46. get { return component.isStopped; }
  47. }
  48. public void Play(bool withChildren = true)
  49. {
  50. component.Play(withChildren);
  51. }
  52. public void Pause(bool withChildren = true)
  53. {
  54. component.Pause(withChildren);
  55. }
  56. public void Stop(bool withChildren = true)
  57. {
  58. component.Stop(withChildren);
  59. }
  60. public bool IsAlive(bool withChildren = true)
  61. {
  62. return component.IsAlive(withChildren);
  63. }
  64. public override void CopyProperties(ParticleSystem source)
  65. {
  66. _playbackSpeed = source.main.simulationSpeed;
  67. }
  68. public override void AdjustProperties(float timeScale)
  69. {
  70. if (timeScale < 0 && !warnedRewind)
  71. {
  72. Debug.LogWarning("Trying to rewind a non-rewindable particle system.", timeline);
  73. warnedRewind = true;
  74. }
  75. var mainSystem = component.main;
  76. mainSystem.simulationSpeed = playbackSpeed * timeScale;
  77. }
  78. }
  79. }