| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Toggles particle system |
| | | 5 | | /// </summary> |
| | | 6 | | [RequireComponent(typeof(ParticleSystem))] |
| | | 7 | | public class ToggleParticle : MonoBehaviour |
| | | 8 | | { |
| | 4 | 9 | | private ParticleSystem currentParticleSystem = null; |
| | 4 | 10 | | private MonoBehaviour currentOwner = null; |
| | | 11 | | |
| | | 12 | | private void Awake() |
| | 2 | 13 | | { |
| | 2 | 14 | | currentParticleSystem = GetComponent<ParticleSystem>(); |
| | 2 | 15 | | } |
| | | 16 | | |
| | | 17 | | public void Play() |
| | 2 | 18 | | { |
| | 2 | 19 | | currentParticleSystem.Play(); |
| | 2 | 20 | | } |
| | | 21 | | |
| | | 22 | | public void Stop() |
| | 3 | 23 | | { |
| | 3 | 24 | | currentParticleSystem.Stop(); |
| | 3 | 25 | | } |
| | | 26 | | |
| | | 27 | | public void PlayWithExclusivity(MonoBehaviour owner) |
| | 0 | 28 | | { |
| | 0 | 29 | | if(currentOwner == null) |
| | 0 | 30 | | { |
| | 0 | 31 | | currentOwner = this; |
| | 0 | 32 | | Play(); |
| | 0 | 33 | | } |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | public void StopWithExclusivity(MonoBehaviour owner) |
| | 1 | 37 | | { |
| | 1 | 38 | | if(currentOwner == this) |
| | 0 | 39 | | { |
| | 0 | 40 | | currentOwner = null; |
| | 0 | 41 | | Stop(); |
| | 0 | 42 | | } |
| | 1 | 43 | | } |
| | | 44 | | |
| | | 45 | | private void OnValidate() |
| | 4 | 46 | | { |
| | 4 | 47 | | if(currentParticleSystem) |
| | 0 | 48 | | { |
| | 0 | 49 | | ParticleSystem.MainModule main = currentParticleSystem.main; |
| | 0 | 50 | | main.playOnAwake = false; |
| | 0 | 51 | | } |
| | 4 | 52 | | } |
| | | 53 | | |
| | | 54 | | public void ToggleParticleSystem() |
| | 7 | 55 | | { |
| | 7 | 56 | | if(currentParticleSystem.isPlaying) |
| | 2 | 57 | | { |
| | 2 | 58 | | currentParticleSystem.Stop(); |
| | 2 | 59 | | } |
| | 5 | 60 | | else currentParticleSystem.Play(); |
| | 7 | 61 | | } |
| | | 62 | | } |