void Update()
 {
     if (lastSpawnTime + SPAWN_INTERVAL < Time.time && numberOfParticles > 0)
     {                                                                                                                 // Is it time already for spawning a new particle?
         GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load(ResourceDirectories.DynamicParticle2)); //Spawn a particle
         newLiquidParticle.GetComponent <Rigidbody2D>().AddForce(particleForce);                                       //Add our custom force
         DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();                          // Get the particle script
         particleScript.SetState(particlesState);                                                                      //Set the particle State
         newLiquidParticle.transform.position = transform.position;                                                    // Relocate to the spawner position
         newLiquidParticle.transform.parent   = particlesParent;                                                       // Add the particle to the parent container
         lastSpawnTime = Time.time;                                                                                    // Register the last spawnTime
         --numberOfParticles;
     }
     else if (numberOfParticles <= 0)
     {
         gameObject.SetActive(false);
     }
 }
Esempio n. 2
0
 void Update()
 {
     if (emit)
     {
         if (lastSpawnTime + SPAWN_INTERVAL < Time.time)
         {                                                                                                            // Is it time already for spawning a new particle?
             GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load("LiquidPhysics/DynamicParticle")); //Spawn a particle
             newLiquidParticle.GetComponent <Rigidbody2D>().AddForce(particleForce);                                  //Add our custom force
             DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();                     // Get the particle script
             particleScript.SetLifeTime(PARTICLE_LIFETIME);                                                           //Set each particle lifetime
             particleScript.SetState(particlesState);                                                                 //Set the particle State
             particleScript.SetColor(color);                                                                          //Set the particle Color
             newLiquidParticle.transform.position = transform.position;                                               // Relocate to the spawner position
             newLiquidParticle.transform.parent   = particlesParent;                                                  // Add the particle to the parent container
             lastSpawnTime = Time.time;                                                                               // Register the last spawnTime
         }
     }
 }
Esempio n. 3
0
        private DynamicParticle StworzCzasteczke(int i) //i pomocnicza
        {
            DynamicParticle czasteczka;
            Random          rand = new Random();
            float           kat  = MathHelper.Lerp(MinObrot, MaxObrot, (float)(i + 1) / (float)Ilosc);
            float           Sin  = (float)Math.Sin(kat);
            float           Cos  = (float)Math.Cos(kat);
            float           DoR  = MathHelper.Lerp(MinDoR, MaxDoR, (float)(rand.Next(0, 100) / 100f));
            float           OdR  = MathHelper.Lerp(MinOdR, MaxOdR, (float)(rand.Next(0, 100) / 100f));

            czasteczka = new DynamicParticle((int)(Sin * OdR + (float)X), (int)(-Cos * OdR + (float)Y), rand.Next(MinSzer, MaxSzer), rand.Next(MinWys, MaxWys),
                                             Color.Lerp(MinSKolor, MaxSKolor, ((float)rand.Next(0, 1000)) / 1000f),
                                             Color.Lerp(MinKKolor, MaxKKolor, ((float)rand.Next(0, 1000)) / 1000f), rand.Next(MinT, MaxT));
            czasteczka.Vmax = 10f; //moze poruszac sie z ogromna predkoscia

            //wpierw oblcize dokad ma doleciec nastepna czasteczka

            Vector2 dokad = new Vector2(Sin * DoR + (float)X, -Cos * DoR + (float)Y);


            switch (Ruch)
            {
            case Rodzaj_Ruchu.RuchJednostajny:
                czasteczka.RuchJednostajny(dokad);
                break;

            case Rodzaj_Ruchu.RuchPrzyspieszony:
                czasteczka.RuchJednostajny(dokad);
                break;
            }
            if (Przyczepiaj)
            {
                czasteczka.Przyczep(PrzyczepienieKto);
            }
            return(czasteczka);
        }
Esempio n. 4
0
        private DynamicParticle StworzCzasteczke(int i) //i pomocnicza
        {
            DynamicParticle czasteczka;
            Random          rand = new Random();

            czasteczka = new DynamicParticle(X, Y, rand.Next(MinSzer, MaxSzer), rand.Next(MinWys, MaxWys),
                                             Color.Lerp(MinSKolor, MaxSKolor, ((float)rand.Next(0, 100)) / 100f),
                                             Color.Lerp(MinKKolor, MaxKKolor, ((float)rand.Next(0, 100)) / 100f), rand.Next(MinT, MaxT));
            czasteczka.Vmax = 100f;


            float helpX = 0f, helpY = 0f;
            float helpobrot = Obrot - (float)Math.PI;


            switch (Ulozenie)
            {
            case Rodzaj_Dziala.Cosinusowe:
            {
                float ile   = (float)(i + 1) / (float)Ilosc * (float)Math.PI;
                float obrot = (float)Math.Sin(ile) * MathHelper.Lerp(MinObrot, MaxObrot, (float)(rand.Next(0, 100) / 100f)) + helpobrot;
                helpX  = (float)Math.Sin(obrot) * MathHelper.Lerp(MinR, MaxR, (float)rand.Next(0, 100) / 100f);
                helpY -= (float)Math.Cos(obrot) * MathHelper.Lerp(MinR, MaxR, (float)rand.Next(0, 100) / 100f);
            }
            break;

            case Rodzaj_Dziala.Losowo:
            {
                float ile   = (float)rand.Next(0, 100) / 100f * (float)Math.PI;
                float obrot = (float)Math.Sin(ile) * MathHelper.Lerp(MinObrot, MaxObrot, (float)(rand.Next(0, 100) / 100f)) + helpobrot;
                helpX  = (float)Math.Sin(obrot) * MathHelper.Lerp(MinR, MaxR, (float)rand.Next(0, 100) / 100f);
                helpY -= (float)Math.Cos(obrot) * MathHelper.Lerp(MinR, MaxR, (float)rand.Next(0, 100) / 100f);
            }
            break;

            case Rodzaj_Dziala.Rownomierne:
            {
                float ile   = (float)(i + 1) / (float)Ilosc;
                float obrot = ile * MathHelper.Lerp(MinObrot, MaxObrot, (float)(rand.Next(0, 100) / 100f)) + helpobrot;
                helpX  = (float)Math.Sin(obrot) * MathHelper.Lerp(MinR, MaxR, (float)rand.Next(0, 100) / 100f);
                helpY -= (float)Math.Cos(obrot) * MathHelper.Lerp(MinR, MaxR, (float)rand.Next(0, 100) / 100f);
            }
            break;
            }



            Vector2 dokad = new Vector2(
                helpX + (float)X,
                helpY + (float)Y);


            switch (Ruch)
            {
            case Rodzaj_Ruchu.RuchJednostajny:
                czasteczka.RuchJednostajny(dokad);
                break;

            case Rodzaj_Ruchu.RuchPrzyspieszony:
                czasteczka.RuchJednostajny(dokad);
                break;
            }
            return(czasteczka);
        }
Esempio n. 5
0
 public static void RemoveParticleFromList(DynamicParticle particle)
 {
     particles.Remove(particle);
 }
Esempio n. 6
0
 public void AddParticleToList(DynamicParticle particle)
 {
     particles.Add(particle);
 }