private void CheckForCollisionsMistParticles() { if (MistParticleSystem == null || CollisionMask == 0) { return; } bool collisionEnabled = (CollisionMask != 0 && CollisionEnabled); if (!collisionEnabled) { return; } int count = MistParticleSystem.GetParticles(particles); bool changes = false; RaycastHit2D hit; for (int i = 0; i < count; i++) { Vector3 pos = particles[i].position; hit = Physics2D.Raycast(pos, particles[i].velocity.normalized, particles[i].velocity.magnitude * Time.deltaTime); if (hit.collider != null && ((1 << hit.collider.gameObject.layer) & CollisionMask) != 0) { particles[i].velocity *= MistCollisionVelocityMultiplier; particles[i].remainingLifetime *= MistCollisionLifeTimeMultiplier; changes = true; } } if (changes) { MistParticleSystem.SetParticles(particles, count); } }
/// <summary> /// Camera pre cull event /// </summary> /// <param name="camera">Camera</param> protected override void OnCameraPreCull(Camera camera) { if (!IsFirstPerson || Intensity == 0.0f || (WeatherMakerPrecipitationManagerScript.Instance != null && WeatherMakerScript.GetCameraType(camera) != WeatherMakerCameraType.Normal && !WeatherMakerPrecipitationManagerScript.Instance.FollowNonNormalCameras)) { return; } #if UNITY_EDITOR else if (camera.cameraType != CameraType.SceneView && camera.name.IndexOf("scenecamera", System.StringComparison.OrdinalIgnoreCase) < 0 && camera.name.IndexOf("prerender", System.StringComparison.OrdinalIgnoreCase) < 0) { #endif // put particle system on the new camera PositionAllElements(camera.transform); // if switching to a new camera, re-emit particles as they need to render around the new camera if (Intensity > 0.0f && Time.timeScale > 0.0f && (lastCamera == null || lastCamera != camera)) { // TODO: Give each camera it's own precipitation // spawn new particles, Unity does not auto-update particle system when it moves, it waits until next frame if (ParticleSystem.isPlaying) { ParticleSystem.Emit((int)Mathf.Round(ParticleSystem.emission.rateOverTime.constant * Time.deltaTime)); ParticleSystem.Simulate(Time.timeScale / 1000.0f, true, false, false); ParticleSystem.Play(true); } if (MistParticleSystem != null && MistParticleSystem.isPlaying && Intensity >= MistThreshold) { MistParticleSystem.Emit((int)Mathf.Round(MistParticleSystem.emission.rateOverTime.constant * Time.deltaTime)); MistParticleSystem.Simulate(Time.timeScale / 1000.0f, true, false, false); MistParticleSystem.Play(true); } if (ParticleSystemSecondary != null && ParticleSystemSecondary.isPlaying && Intensity >= SecondaryThreshold) { ParticleSystemSecondary.Emit((int)Mathf.Round(ParticleSystemSecondary.emission.rateOverTime.constant * Time.deltaTime)); ParticleSystemSecondary.Simulate(Time.timeScale / 1000.0f, true, false, false); ParticleSystemSecondary.Play(true); } } lastCamera = camera; #if UNITY_EDITOR } #endif }