IsPlaying.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityParticleSystem
  3. {
  4. [TaskCategory("Unity/ParticleSystem")]
  5. [TaskDescription("Is the Particle System playing?")]
  6. public class IsPlaying : Conditional
  7. {
  8. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  9. public SharedGameObject targetGameObject;
  10. private ParticleSystem particleSystem;
  11. private GameObject prevGameObject;
  12. public override void OnStart()
  13. {
  14. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  15. if (currentGameObject != prevGameObject) {
  16. particleSystem = currentGameObject.GetComponent<ParticleSystem>();
  17. prevGameObject = currentGameObject;
  18. }
  19. }
  20. public override TaskStatus OnUpdate()
  21. {
  22. if (particleSystem == null) {
  23. Debug.LogWarning("ParticleSystem is null");
  24. return TaskStatus.Failure;
  25. }
  26. return particleSystem.isPlaying ? TaskStatus.Success : TaskStatus.Failure;
  27. }
  28. public override void OnReset()
  29. {
  30. targetGameObject = null;
  31. }
  32. }
  33. }