Stop.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityParticleSystem
  3. {
  4. [TaskCategory("Unity/ParticleSystem")]
  5. [TaskDescription("Stop the Particle System.")]
  6. public class Stop : Action
  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. particleSystem.Stop();
  27. return TaskStatus.Success;
  28. }
  29. public override void OnReset()
  30. {
  31. targetGameObject = null;
  32. }
  33. }
  34. }