Ejemplo n.º 1
0
    private void Awake()
    {
        this.mf  = GetComponent <MeshFilter>();
        this.rnd = GetComponent <MeshRenderer>();

        ringCount    = Mathf.CeilToInt((ringMaxLifetime / emissionInterval)) + 1;
        vertsPerRing = angularSegments + 1;
        vertexCount  = ringCount * vertsPerRing;
        quadCount    = (ringCount - 1) * angularSegments;

        mesh = new Mesh();
        mesh.MarkDynamic();
        mf.sharedMesh = mesh;

        particleRings = new ParticleRing[ringCount];
        for (int i = 0; i < ringCount; i++)
        {
            particleRings[i] = new ParticleRing();
            SetParticleRingSpawnPos(particleRings[i]);
            if (i > 0)
            {
                particleRings[i].active = false;
            }
        }

        triangleIndices = new int[quadCount * 2 * 3];
        vertices        = new Vector3[vertexCount];
        uv0             = new List <Vector3>(vertexCount);
        for (int i = 0; i < vertexCount; i++)
        {
            uv0.Add(default(Vector3));
        }
    }
        public override void UpdateSwarmPositions(ParticleRing<SwarmParticle> particles)
        {
            for (int i = 0; i < particles.Count(); i++)
            {
                SwarmParticle center = particles.ElementAt(i);
                List<SwarmParticle> neighbours = particles.GetNAdjacentParticles(i, NeighbourhoodSize);

                neighbours.OrderBy(n => n.GetCurrentFitness());

                UpdateParticle(center, neighbours.Last());
            }
        }
Ejemplo n.º 3
0
 void SetParticleRingSpawnPos(ParticleRing ring)
 {
     for (int i = 0; i < angularSegments; i++)
     {
         PosDir posDir = GetSpawnCoordinate(i);
         if (ring.particles == null)
         {
             ring.particles = new Particle[angularSegments];
             for (int p = 0; p < angularSegments; p++)
             {
                 ring.particles[p] = new Particle();
             }
         }
         ring.particles[i].position = posDir.pos;
         ring.particles[i].velocity = posDir.dir * emissionSpeed;
         particleRings[emissionRootRingIndex].spawnTime = Time.time;
         particleRings[emissionRootRingIndex].lifeTime  = 0;
     }
 }
 public override void UpdateSwarmPositions(ParticleRing<SwarmParticle> particles)
 {
     //not needed at the moment, don't do anything
 }