| using System; |
| using System; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class DistantFogEmitter : MonoBehaviour |
| public class DistantFogEmitter : MonoBehaviour |
| { |
| { |
| public void SetEmit(bool emit) |
| public void SetEmit(bool emit) |
| { |
| { |
| this.m_emit = emit; |
| this.m_emit = emit; |
| } |
| } |
| |
| |
| private void Update() |
| private void Update() |
| { |
| { |
| if (!this.m_emit) |
| if (!this.m_emit) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (WorldGenerator.instance == null) |
| if (WorldGenerator.instance == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_placeTimer += Time.deltaTime; |
| this.m_placeTimer += Time.deltaTime; |
| if (this.m_placeTimer > this.m_interval) |
| if (this.m_placeTimer > this.m_interval) |
| { |
| { |
| this.m_placeTimer = 0f; |
| this.m_placeTimer = 0f; |
| int num = Mathf.Max(0, this.m_particles - this.TotalNrOfParticles()); |
| int num = Mathf.Max(0, this.m_particles - this.TotalNrOfParticles()); |
| num /= 4; |
| num /= 4; |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| this.PlaceOne(); |
| this.PlaceOne(); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private int TotalNrOfParticles() |
| private int TotalNrOfParticles() |
| { |
| { |
| int num = 0; |
| int num = 0; |
| foreach (ParticleSystem particleSystem in this.m_psystems) |
| foreach (ParticleSystem particleSystem in this.m_psystems) |
| { |
| { |
| num += particleSystem.particleCount; |
| num += particleSystem.particleCount; |
| } |
| } |
| return num; |
| return num; |
| } |
| } |
| |
| |
| private void PlaceOne() |
| private void PlaceOne() |
| { |
| { |
| Vector3 vector; |
| Vector3 vector; |
| if (this.GetRandomPoint(base.transform.position, out vector)) |
| if (this.GetRandomPoint(base.transform.position, out vector)) |
| { |
| { |
| ParticleSystem.EmitParams emitParams = default(ParticleSystem.EmitParams); |
| ParticleSystem.EmitParams emitParams = default(ParticleSystem.EmitParams); |
| emitParams.position = vector + Vector3.up * this.m_placeOffset; |
| emitParams.position = vector + Vector3.up * this.m_placeOffset; |
| this.m_psystems[UnityEngine.Random.Range(0, this.m_psystems.Length)].Emit(emitParams, 1); |
| this.m_psystems[UnityEngine.Random.Range(0, this.m_psystems.Length)].Emit(emitParams, 1); |
| } |
| } |
| } |
| } |
| |
| |
| private bool GetRandomPoint(Vector3 center, out Vector3 p) |
| private bool GetRandomPoint(Vector3 center, out Vector3 p) |
| { |
| { |
| float num = UnityEngine.Random.value * 3.1415927f * 2f; |
| float num = UnityEngine.Random.value * 3.1415927f * 2f; |
| float num2 = Mathf.Sqrt(UnityEngine.Random.value) * (this.m_maxRadius - this.m_minRadius) + this.m_minRadius; |
| float num2 = Mathf.Sqrt(UnityEngine.Random.value) * (this.m_maxRadius - this.m_minRadius) + this.m_minRadius; |
| p = center + new Vector3(Mathf.Sin(num) * num2, 0f, Mathf.Cos(num) * num2); |
| p = center + new Vector3(Mathf.Sin(num) * num2, 0f, Mathf.Cos(num) * num2); |
| p.y = WorldGenerator.instance.GetHeight(p.x, p.z); |
| p.y = WorldGenerator.instance.GetHeight(p.x, p.z); |
| . | if (p.y < ZoneSystem.instance.m_waterLevel) |
| if (p.y < 30f) |
| { |
| { |
| if (this.m_skipWater) |
| if (this.m_skipWater) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (UnityEngine.Random.value > this.m_waterSpawnChance) |
| if (UnityEngine.Random.value > this.m_waterSpawnChance) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| . | p.y = ZoneSystem.instance.m_waterLevel; |
| p.y = 30f; |
| } |
| } |
| else if (p.y > this.m_mountainLimit) |
| else if (p.y > this.m_mountainLimit) |
| { |
| { |
| if (UnityEngine.Random.value > this.m_mountainSpawnChance) |
| if (UnityEngine.Random.value > this.m_mountainSpawnChance) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| } |
| } |
| else if (UnityEngine.Random.value > this.m_landSpawnChance) |
| else if (UnityEngine.Random.value > this.m_landSpawnChance) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| public float m_interval = 1f; |
| public float m_interval = 1f; |
| |
| |
| public float m_minRadius = 100f; |
| public float m_minRadius = 100f; |
| |
| |
| public float m_maxRadius = 500f; |
| public float m_maxRadius = 500f; |
| |
| |
| public float m_mountainSpawnChance = 1f; |
| public float m_mountainSpawnChance = 1f; |
| |
| |
| public float m_landSpawnChance = 0.5f; |
| public float m_landSpawnChance = 0.5f; |
| |
| |
| public float m_waterSpawnChance = 0.25f; |
| public float m_waterSpawnChance = 0.25f; |
| |
| |
| public float m_mountainLimit = 120f; |
| public float m_mountainLimit = 120f; |
| |
| |
| public float m_emitStep = 10f; |
| public float m_emitStep = 10f; |
| |
| |
| public int m_emitPerStep = 10; |
| public int m_emitPerStep = 10; |
| |
| |
| public int m_particles = 100; |
| public int m_particles = 100; |
| |
| |
| public float m_placeOffset = 1f; |
| public float m_placeOffset = 1f; |
| |
| |
| public ParticleSystem[] m_psystems; |
| public ParticleSystem[] m_psystems; |
| |
| |
| public bool m_skipWater; |
| public bool m_skipWater; |
| |
| |
| private float m_placeTimer; |
| private float m_placeTimer; |
| |
| |
| private bool m_emit = true; |
| private bool m_emit = true; |
| |
| |
| private Vector3 m_lastPosition = Vector3.zero; |
| private Vector3 m_lastPosition = Vector3.zero; |
| } |
| } |
| |
| |