public void DoUpdate(float deltaTime) { Vector3 spawnPosition, offset, offsetStep = Vector3.zero; Vector3 spawnDirection, dir, dirStep = Vector3.zero; float spawnSpeed, age = 0f; //float spd,spdStep = 0f; int j, index, localSubCounter = 0; float step = 1f / emitter.spawnRate; float subParticlesRatio = emitter.subParticlesRatio; int subParticlesCounter = emitter.subParticlesCounter; int subParticlesCount = emitter.subParticlesCount; float ratio = deltaTime / step; int spawnCount = Mathf.FloorToInt(ratio); float lifeTime = emitter.lifeTime; float startSize = emitter.startSize; float endSize = emitter.endSize; Color startColor = emitter.startColor; Color endColor = emitter.endColor; Puffy_ParticleData particle; float maxParticlesDistance = emitter.maxParticlesDistance; float localRatio, localStep; int localSpawnCount; spawnSpeed = emitter.startSpeed; foreach (Puffy_ParticleSpawner spawner in spawnerList) { localSubCounter = subParticlesCounter; if (spawner.enabled) { localRatio = ratio; localSpawnCount = spawnCount; localStep = step; age = deltaTime; offset = spawner.spawnPosition - spawner.lastPosition; offsetStep = offset / localRatio; if (maxParticlesDistance > 0) { float magnitude = offsetStep.magnitude; if (magnitude > maxParticlesDistance) { localRatio = offset.magnitude / maxParticlesDistance; localSpawnCount = Mathf.FloorToInt(localRatio); if (localSpawnCount < spawnCount * 10) { offsetStep = offset.normalized * maxParticlesDistance; localStep = (spawnCount * step) / localSpawnCount; } else { localRatio = ratio; localSpawnCount = spawnCount; } } } spawnPosition = spawner.lastPosition; dir = spawner.particleDirection - spawner.lastParticleDirection; dirStep = dir / localRatio; spawnDirection = spawner.lastParticleDirection; /* * spd = spawner.particleSpeed - spawner.lastParticleSpeed; * spdStep = spd / localRatio; * spawnSpeed = spawner.lastParticleSpeed; */ for (j = 0; j < localSpawnCount; j++) { spawnPosition += offsetStep; spawnDirection += dirStep; //spawnSpeed += spdStep; index = emitter.SpawnParticle(spawnPosition, spawnDirection, spawnSpeed, lifeTime, startSize, endSize, startColor, endColor, age); age -= localStep; if (index >= 0 && subParticlesCount > 0) { particle = emitter.particles[index]; if (localSubCounter < subParticlesCount) { particle.startLifetime *= subParticlesRatio; particle.endSize *= subParticlesRatio; if (emitter.debugIntermediate) { particle.startColor = Color.yellow; particle.endColor = Color.yellow; } } else { if (emitter.debugIntermediate) { particle.startColor = Color.magenta; particle.endColor = Color.magenta; } localSubCounter = 0; } localSubCounter++; } } spawner.lastPosition = spawnPosition; spawner.lastParticleDirection = spawnDirection; // spawner.lastParticleSpeed = spawnSpeed; } } emitter.subParticlesCounter = localSubCounter; particle = null; }
// Use this for initialization void Build() { if (subCount < 0) { subCount = 0; } if (baseCount < 0) { baseCount = 0; } _randomSeed = randomSeed; _subCount = subCount; _baseCount = baseCount; int i, j; Vector3 pos, pos2; float size, size2; List <int> existingParticles = new List <int>(); for (i = 0; i < particlesList.Count; i++) { existingParticles.Add(particlesList[i]); } particlesList.Clear(); particlesPositions.Clear(); particlesSizes.Clear(); _position += Vector3.one; int index = 0; for (i = 0; i < baseCount; i++) { //Random.seed = randomSeed + i; pos = Random.insideUnitSphere * emitter.startSize * 0.2f; size = Random.Range(emitter.startSize, emitter.endSize); if (existingParticles.Count > 0) { index = existingParticles[0]; existingParticles.RemoveAt(0); emitter.particles[index].position = pos; emitter.particles[index].size = size; emitter.particles[index].startSize = size; emitter.particles[index].endSize = size; emitter.particles[index].startLifetime = -1; emitter.particles[index].lifetime = 0; emitter.particles[index].speed = 0; emitter.particles[index].startColor = emitter.startColor; emitter.particles[index].endColor = emitter.endColor; } else { index = emitter.SpawnParticle(pos, Vector3.zero, 0, -1, size, size, emitter.startColor, emitter.endColor, 0); } if (index >= 0) { particlesList.Add(index); particlesPositions.Add(pos); particlesSizes.Add(size); for (j = 0; j < subCount; j++) { //Random.seed = randomSeed + 100 + j*5; pos2 = pos + Random.onUnitSphere * size * 0.2f; size2 = Random.Range(emitter.startSize * 0.5f, emitter.endSize * 0.3f); if (existingParticles.Count > 0) { index = existingParticles[0]; existingParticles.RemoveAt(0); emitter.particles[index].position = pos2; emitter.particles[index].size = size2; emitter.particles[index].startSize = size2; emitter.particles[index].endSize = size2; emitter.particles[index].startLifetime = -1; emitter.particles[index].lifetime = 0; emitter.particles[index].speed = 0; emitter.particles[index].startColor = emitter.startColor; emitter.particles[index].endColor = emitter.endColor; } else { index = emitter.SpawnParticle(pos2, Vector3.zero, 0, -1, size2, size2, emitter.startColor, emitter.endColor, 0); } if (index >= 0) { particlesList.Add(index); particlesPositions.Add(pos2); particlesSizes.Add(size2); } } } } for (i = 0; i < existingParticles.Count; i++) { emitter.KillParticle(existingParticles[i]); } built = true; }
public void DoUpdate(float deltaTime) { int count = vertices.Length; Vector3 transformedPosition = Vector3.zero; Vector3 transformedDirection = Vector3.zero; Vector3 spawnPosition, offset, offsetStep = Vector3.zero; Vector3 spawnDirection, dir, dirStep = Vector3.zero; float spawnSpeed, spd, spdStep, age = 0f; int i, j, index, localSubCounter = 0; float step = 1f / emitter.spawnRate; float subParticlesRatio = emitter.subParticlesRatio; int subParticlesCounter = emitter.subParticlesCounter; int subParticlesCount = emitter.subParticlesCount; float ratio = deltaTime / step; int spawnCount = Mathf.FloorToInt(ratio); float lifeTime = emitter.lifeTime; float startSize = emitter.startSize; float endSize = emitter.endSize; Color startColor = emitter.startColor; Color endColor = emitter.endColor; Puffy_Emitter.colorModes colorMode = emitter.colorMode; Puffy_ParticleData particle; float maxParticlesDistance = emitter.maxParticlesDistance; float localRatio, localStep; int localSpawnCount; for (i = 0; i < count; i += emitEveryNthPoint) { localSubCounter = subParticlesCounter; localRatio = ratio; localSpawnCount = spawnCount; localStep = step; if (true) { transformedPosition = _transform.TransformPoint(vertices[i]); transformedDirection = _transform.TransformDirection(normals[i]); age = deltaTime; offset = transformedPosition - lastSpawnPosition[i]; offsetStep = offset / localRatio; if (maxParticlesDistance > 0) { float magnitude = offsetStep.magnitude; if (magnitude > maxParticlesDistance) { localRatio = offset.magnitude / maxParticlesDistance; localSpawnCount = Mathf.FloorToInt(localRatio); if (localSpawnCount < spawnCount * 10) { offsetStep = offset.normalized * maxParticlesDistance; localStep = (spawnCount * step) / localSpawnCount; } else { localRatio = ratio; localSpawnCount = spawnCount; } } } spawnPosition = lastSpawnPosition[i]; dir = transformedDirection - lastSpawnDirection[i]; dirStep = dir / localRatio; spawnDirection = lastSpawnDirection[i]; spd = particleSpeed - lastParticleSpeed; spdStep = spd / localRatio; spawnSpeed = lastParticleSpeed; for (j = 0; j < localSpawnCount; j++) { spawnPosition += offsetStep; spawnDirection += dirStep; spawnSpeed += spdStep; index = -1; switch (colorMode) { case Puffy_Emitter.colorModes.Basic: case Puffy_Emitter.colorModes.Gradient: index = emitter.SpawnParticle(spawnPosition, spawnDirection, spawnSpeed, lifeTime, startSize, endSize, startColor, endColor, age); break; case Puffy_Emitter.colorModes.Mesh: index = emitter.SpawnParticle(spawnPosition, spawnDirection, spawnSpeed, lifeTime, startSize, endSize, colors[i], colors[i], age); break; } age -= localStep; if (index >= 0 && subParticlesCount > 0) { particle = emitter.particles[index]; if (localSubCounter < subParticlesCount) { particle.startLifetime *= subParticlesRatio; particle.endSize *= subParticlesRatio; if (emitter.debugIntermediate) { particle.startColor = Color.yellow; particle.endColor = Color.yellow; } } else { if (emitter.debugIntermediate) { particle.startColor = Color.magenta; particle.endColor = Color.magenta; } localSubCounter = 0; } localSubCounter++; } } lastSpawnPosition[i] = spawnPosition; lastSpawnDirection[i] = spawnDirection; lastParticleSpeed = spawnSpeed; } } emitter.subParticlesCounter = localSubCounter; particle = null; }