private void ProcessVertices(Vector3[] verts, Color[] colors, Vector3 velocity) { if (verts == null || colors == null) { Debug.Log("no verts"); return; } velocity = Vector3.ClampMagnitude(velocity, _maxForceMagnitude); CheckParticles(); var vertexMulti = Mathf.Clamp(_maxParticles / verts.Length, 1, 2); var emitCount = Mathf.Clamp(verts.Length * vertexMulti, 100, _maxParticles); //_particleSystem.main.maxParticles = _maxParticles; _particleSystem.Emit(emitCount); var currentParticlesCount = _particleSystem.GetParticles(_particles); //if (currentParticlesCount != emitCount && !Application.isPlaying) { // Debug.LogError(string.Format("Particle count {0} emit {1}", currentParticlesCount, emitCount)); //} var vertexStep = verts.Length / _maxParticles; if (vertexStep < 1) { vertexStep = 1; } var vertIndex = 0; float jitter = _extraForce.Get(); float posJitter = 0; //var octaves = 1; for (int i = 0; i < currentParticlesCount; i++) { var spherePos = UnityEngine.Random.insideUnitSphere; _particles[i].position = verts[vertIndex] + spherePos * posJitter; //targetTr.TransformPoint(verts[vertIndex]); //verts[vertIndex];// _particles[i].startColor = colors[vertIndex]; var noiseOffset = Mathf.PerlinNoise(_particles[i].position.x, _particles[i].position.y); //Perlin.Fbm(verts[vertIndex], octaves); _particles[i].velocity = velocity + spherePos * jitter * noiseOffset; _particles[i].angularVelocity3D = velocity + spherePos * jitter * noiseOffset; vertIndex += vertexStep; if (vertIndex >= verts.Length) { //octaves++; vertIndex = 0; posJitter += _particleSystem.main.startSize.Evaluate(0.5f); jitter += _extraForce.Get(); } } _particleSystem.SetParticles(_particles, emitCount); if (Application.isPlaying) { TimeManager.StartTask(DespawnParticles()); } }
public void Fire(Vector3 targetPos) { var position = ShootPivot.Tr.position; ProjectileFactory.SpawnProjectile(this.GetEntity(), ProjectileId, targetPos, position, Quaternion.LookRotation(targetPos - position)); ShootTimer.StartNewTime(ShootCooldown.Get()); }