void Awake() { // Singleton pattern: instance = this; // Instantiate our particle list: particles = new List <GameObject>(); }
//------------------------------------------------------ Public Particle Functions ----------------------------------------------\\ /// <summary> /// Play a particle. /// <para>If you don't have a particle to play, use the FindParticle function.</para> /// </summary> /// <param name="toPlay">The particlesystem that will be played</param> /// <param name="position">position in world space where the particle will be played at</param> /// <param name="rotation">rotation in world space how the particle will be played.</param> public int PlayParticle(ParticleSystem toPlay, Vector3 position, Quaternion rotation, Transform toFollow = null, bool posInWorldSpace = true) { ParticleTracker system = CreateNewParticleSystem(toPlay); if (posInWorldSpace || toFollow == null) { system.reference.transform.position = position; } system.reference.transform.rotation = rotation; system.reference.Play(); if (toFollow != null) { system.reference.transform.SetParent(toFollow); } if (!posInWorldSpace && toFollow != null) { system.reference.transform.localPosition = position; } if (!system.reference.main.loop) { system.deathTimer = StartCoroutine(system.ParticleDeathTimer()); } return(system.ID); }
//------------------------------------------------------ Private Particle Functions ----------------------------------------------\\ private ParticleTracker CreateNewParticleSystem(ParticleSystem system) { ParticleSystem pSystem = Instantiate(system.gameObject, transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); ParticleTracker toReturn = FindAvailableParticleTracker(); toReturn.CreateReference(pSystem); return(toReturn); }
public void StopParticle(int particleID) { ParticleTracker toStop = FindActiveParticle(particleID); if (toStop.deathTimer != null) { StopCoroutine(toStop.deathTimer); } StartCoroutine(toStop.Stop()); }
private ParticleTracker FindAvailableParticleTracker() { for (int i = 0; i < activeParticleSystems.Count; i++) { if (!activeParticleSystems[i].referenceIsSet) { return(activeParticleSystems[i]); } } ParticleTracker toReturn = new ParticleTracker(activeParticleSystems.Count); activeParticleSystems.Add(toReturn); return(toReturn); }