ScriptPlayableTrackParticle.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. using UnityEngine.UI;
  6. // A behaviour that is attached to a playable
  7. public class ScriptPlayableTrackParticle : PlayableBehaviour
  8. {
  9. public ParticleSystem particles;
  10. private ParticleSystem.EmissionModule particlesEmission;
  11. public ParticleTLType location = ParticleTLType.NpcBody;
  12. public int masterId;
  13. public string point;
  14. public string placeName;
  15. public bool startEnabled;
  16. public bool endEnabled;
  17. public Color particleColour = Color.white;
  18. public StoryMgr mgr;
  19. public void Init(ParticleSystem particles, ParticleTLType location, int masterId, string point, string placeName, bool startEnabled, bool endEnabled, Color particleColour, StoryMgr mgr)
  20. {
  21. this.mgr = mgr;
  22. this.particles = particles;
  23. if (particles != null)
  24. particlesEmission = particles.emission;
  25. this.location = location;
  26. this.masterId = masterId;
  27. this.point = point;
  28. this.placeName = placeName;
  29. this.startEnabled = startEnabled;
  30. this.endEnabled = endEnabled;
  31. this.particleColour = particleColour;
  32. this.mgr = mgr;
  33. }
  34. // Called when the owning graph starts playing
  35. public override void OnGraphStart(Playable playable)
  36. {
  37. //Debug.Log("OnGraphStart");
  38. }
  39. // Called when the owning graph stops playing
  40. public override void OnGraphStop(Playable playable)
  41. {
  42. //Debug.Log("OnGraphStop");
  43. }
  44. // Called when the state of the playable is set to Play
  45. public override void OnBehaviourPlay(Playable playable, FrameData info)
  46. {
  47. if (particles == null)
  48. return;
  49. particlesEmission.enabled = startEnabled;
  50. ParticleSystem.MainModule mainModule = particles.main;
  51. ParticleSystem.MinMaxGradient colourGradient = new ParticleSystem.MinMaxGradient(particleColour);
  52. mainModule.startColor = colourGradient;
  53. if (mgr)
  54. mgr.BindParticle2Place(particles, masterId, placeName, location);
  55. else
  56. StoryMgr.Instance.BindParticle2Place(particles, masterId, placeName, location);
  57. }
  58. public override void OnBehaviourPause(Playable playable, FrameData info)
  59. {
  60. //Debug.Log("pause");
  61. if (particles == null)
  62. return;
  63. particlesEmission.enabled = endEnabled;
  64. }
  65. }