public Particle RequestParticle(sSubstance substanceRequested) { // If the list is empty return null. if (notInUse.Count <= 0) { // Create a new substance for the empty list. GameObject substanceInstance = Instantiate(particlePrefab, transform); Particle substanceScript = substanceInstance.GetComponent <Particle> (); substanceScript.Deactivate(); notInUse.Add(substanceScript); // Debug to increase the number. Debug.Log("The object pool went over " + MAX_Particules); } // Select the first particle. Particle particleScript = notInUse [0]; // Update the list. notInUse.Remove(particleScript); inUse.Add(particleScript); // Activate the substance. particleScript.Activate(substanceRequested); return(particleScript); }
void Start() { StartCoroutine(IELifetime(maxLifeTime)); if (flightParticle != null) { flightParticle.Activate(true); } //transform.RotateAround(transform.position, Vector3.forward, 90f); if (body) { transform.right = body.velocity.normalized; body.AddTorque(torque); } }
/// <summary> /// Spawn this particle into a position and activate it /// </summary> /// <param name="pos"></param> public void Spawn(Vector2 pos) { try { Particle particle = availableExplosionParticle[Random.Range(0, availableExplosionParticle.Count)].GetComponent <Particle>(); particle.Activate(pos); availableExplosionParticle.Remove(particle.GetComponent <ParticleSystem>()); } catch { Particle particle = Create().GetComponent <Particle>(); particle.Activate(pos); } }
private void Discharge(GameTime time) { //Flag set to true if a Particle is emitted... bool emitted = false; //Cycle through each Snapshot... while (_snapshots.Count > 0) { //Get the latest Emitter Snapshot... Snapshot snap = _snapshots.Dequeue(); _snapCache.Enqueue(snap); //Discharge the correct number of Particles... for (int i = 0; i < _dischargeQuantity; i++) { //If there are no available idle Particles... if (_idle.Count == 0) { //Raise starving event... RaiseEvent(Starving); return; } //Get a fresh Particle from the idle Particles queue... Particle spawn = _idle.Dequeue(); spawn.Activate(time, _lifespan); _active.AddLast(spawn); //Do stuff to the Particle here... spawn.Color = new Vector4(_color.ToVector3(), _opacity); spawn.Scale = _scale; GetParticlePositionAndOrientation(snap, ref spawn.Position, ref spawn.Momentum); //spawn.Position += snap.Position; Vector2.Add(ref spawn.Position, ref snap.Position, out spawn.Position); float speed = MathHelper.Lerp(_speed - (_speedRange / 2f), _speed + (_speedRange / 2f), (float)Rnd.NextDouble()); //spawn.Momentum *= speed; Vector2.Multiply(ref spawn.Momentum, speed, out spawn.Momentum); //Send the new Particle to the Modifiers... _modifiers.ForEach(delegate(Modifier mod) { mod.ProcessNewParticle(time, spawn); }); emitted = true; } } //If a particle has been emitted... if (emitted) { //Raise discharging event... RaiseEvent(Discharging); if (_sleeping) { //Raise waking event... RaiseEvent(Waking); _sleeping = false; } } }