| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| . | public class Smoke : MonoBehaviour |
| public class Smoke : MonoBehaviour, IMonoUpdater |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| Smoke.s_smoke.Add(this); |
| Smoke.s_smoke.Add(this); |
| this.m_added = true; |
| this.m_added = true; |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_body = base.GetComponent<Rigidbody>(); |
| this.m_mr = base.GetComponent<MeshRenderer>(); |
| this.m_mr = base.GetComponent<MeshRenderer>(); |
| this.m_propertyBlock = new MaterialPropertyBlock(); |
| this.m_propertyBlock = new MaterialPropertyBlock(); |
| Color color = this.m_mr.material.color; |
| Color color = this.m_mr.material.color; |
| color.a = 0f; |
| color.a = 0f; |
| this.m_propertyBlock.SetColor(Smoke.m_colorProp, color); |
| this.m_propertyBlock.SetColor(Smoke.m_colorProp, color); |
| this.m_propertyBlock.SetFloat(Smoke.m_randomAngleProp, UnityEngine.Random.Range(0f, 6.2831855f)); |
| this.m_propertyBlock.SetFloat(Smoke.m_randomAngleProp, UnityEngine.Random.Range(0f, 6.2831855f)); |
| this.m_mr.SetPropertyBlock(this.m_propertyBlock); |
| this.m_mr.SetPropertyBlock(this.m_propertyBlock); |
| this.m_body.maxDepenetrationVelocity = 1f; |
| this.m_body.maxDepenetrationVelocity = 1f; |
| . | this.m_vel += Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * this.m_randomVel; |
| this.m_vel = Vector3.up + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * this.m_randomVel; |
| } |
| } |
| |
| |
| private void OnEnable() |
| private void OnEnable() |
| { |
| { |
| Smoke.Instances.Add(this); |
| Smoke.Instances.Add(this); |
| } |
| } |
| |
| |
| private void OnDisable() |
| private void OnDisable() |
| { |
| { |
| Smoke.Instances.Remove(this); |
| Smoke.Instances.Remove(this); |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| if (this.m_added) |
| if (this.m_added) |
| { |
| { |
| Smoke.s_smoke.Remove(this); |
| Smoke.s_smoke.Remove(this); |
| this.m_added = false; |
| this.m_added = false; |
| } |
| } |
| } |
| } |
| |
| |
| public void StartFadeOut() |
| public void StartFadeOut() |
| { |
| { |
| if (this.m_fadeTimer >= 0f) |
| if (this.m_fadeTimer >= 0f) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_added) |
| if (this.m_added) |
| { |
| { |
| Smoke.s_smoke.Remove(this); |
| Smoke.s_smoke.Remove(this); |
| this.m_added = false; |
| this.m_added = false; |
| } |
| } |
| this.m_fadeTimer = 0f; |
| this.m_fadeTimer = 0f; |
| } |
| } |
| |
| |
| public static int GetTotalSmoke() |
| public static int GetTotalSmoke() |
| { |
| { |
| return Smoke.s_smoke.Count; |
| return Smoke.s_smoke.Count; |
| } |
| } |
| |
| |
| public static void FadeOldest() |
| public static void FadeOldest() |
| { |
| { |
| if (Smoke.s_smoke.Count == 0) |
| if (Smoke.s_smoke.Count == 0) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Smoke.s_smoke[0].StartFadeOut(); |
| Smoke.s_smoke[0].StartFadeOut(); |
| } |
| } |
| |
| |
| public static void FadeMostDistant() |
| public static void FadeMostDistant() |
| { |
| { |
| if (Smoke.s_smoke.Count == 0) |
| if (Smoke.s_smoke.Count == 0) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Camera mainCamera = Utils.GetMainCamera(); |
| Camera mainCamera = Utils.GetMainCamera(); |
| if (mainCamera == null) |
| if (mainCamera == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| Vector3 position = mainCamera.transform.position; |
| Vector3 position = mainCamera.transform.position; |
| int num = -1; |
| int num = -1; |
| float num2 = 0f; |
| float num2 = 0f; |
| for (int i = 0; i < Smoke.s_smoke.Count; i++) |
| for (int i = 0; i < Smoke.s_smoke.Count; i++) |
| { |
| { |
| float num3 = Vector3.Distance(Smoke.s_smoke[i].transform.position, position); |
| float num3 = Vector3.Distance(Smoke.s_smoke[i].transform.position, position); |
| if (num3 > num2) |
| if (num3 > num2) |
| { |
| { |
| num = i; |
| num = i; |
| num2 = num3; |
| num2 = num3; |
| } |
| } |
| } |
| } |
| if (num != -1) |
| if (num != -1) |
| { |
| { |
| Smoke.s_smoke[num].StartFadeOut(); |
| Smoke.s_smoke[num].StartFadeOut(); |
| } |
| } |
| } |
| } |
| |
| |
| . | public void CustomUpdate(float deltaTime) |
| public void CustomUpdate(float deltaTime, float time) |
| { |
| { |
| this.m_alpha = Mathf.Clamp01(this.m_time); |
| this.m_alpha = Mathf.Clamp01(this.m_time); |
| this.m_time += deltaTime; |
| this.m_time += deltaTime; |
| if (this.m_time > this.m_ttl && this.m_fadeTimer < 0f) |
| if (this.m_time > this.m_ttl && this.m_fadeTimer < 0f) |
| { |
| { |
| this.StartFadeOut(); |
| this.StartFadeOut(); |
| } |
| } |
| float num = 1f - Mathf.Clamp01(this.m_time / this.m_ttl); |
| float num = 1f - Mathf.Clamp01(this.m_time / this.m_ttl); |
| this.m_body.mass = num * num; |
| this.m_body.mass = num * num; |
| Vector3 velocity = this.m_body.velocity; |
| Vector3 velocity = this.m_body.velocity; |
| Vector3 vel = this.m_vel; |
| Vector3 vel = this.m_vel; |
| vel.y *= num; |
| vel.y *= num; |
| Vector3 vector = vel - velocity; |
| Vector3 vector = vel - velocity; |
| . | this.m_body.AddForce(vector * this.m_force * deltaTime, ForceMode.VelocityChange); |
| this.m_body.AddForce(vector * (this.m_force * deltaTime), ForceMode.VelocityChange); |
| if (this.m_fadeTimer >= 0f) |
| if (this.m_fadeTimer >= 0f) |
| { |
| { |
| this.m_fadeTimer += deltaTime; |
| this.m_fadeTimer += deltaTime; |
| float num2 = 1f - Mathf.Clamp01(this.m_fadeTimer / this.m_fadetime); |
| float num2 = 1f - Mathf.Clamp01(this.m_fadeTimer / this.m_fadetime); |
| this.m_alpha *= num2; |
| this.m_alpha *= num2; |
| if (this.m_fadeTimer >= this.m_fadetime) |
| if (this.m_fadeTimer >= this.m_fadetime) |
| { |
| { |
| UnityEngine.Object.Destroy(base.gameObject); |
| UnityEngine.Object.Destroy(base.gameObject); |
| } |
| } |
| } |
| } |
| if (this.m_time <= 1f || this.m_fadeTimer > 0f) |
| if (this.m_time <= 1f || this.m_fadeTimer > 0f) |
| { |
| { |
| Color color = this.m_propertyBlock.GetColor(Smoke.m_colorProp); |
| Color color = this.m_propertyBlock.GetColor(Smoke.m_colorProp); |
| color.a = this.m_alpha; |
| color.a = this.m_alpha; |
| this.m_propertyBlock.SetColor(Smoke.m_colorProp, color); |
| this.m_propertyBlock.SetColor(Smoke.m_colorProp, color); |
| this.m_mr.SetPropertyBlock(this.m_propertyBlock); |
| this.m_mr.SetPropertyBlock(this.m_propertyBlock); |
| } |
| } |
| } |
| } |
| |
| |
| . | public static List<Smoke> Instances { get; } = new List<Smoke>(); |
| public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); |
| |
| |
| public Vector3 m_vel = Vector3.up; |
| public Vector3 m_vel = Vector3.up; |
| |
| |
| public float m_randomVel = 0.1f; |
| public float m_randomVel = 0.1f; |
| |
| |
| public float m_force = 0.1f; |
| public float m_force = 0.1f; |
| |
| |
| public float m_ttl = 10f; |
| public float m_ttl = 10f; |
| |
| |
| public float m_fadetime = 3f; |
| public float m_fadetime = 3f; |
| |
| |
| private Rigidbody m_body; |
| private Rigidbody m_body; |
| |
| |
| private float m_time; |
| private float m_time; |
| |
| |
| private float m_fadeTimer = -1f; |
| private float m_fadeTimer = -1f; |
| |
| |
| private bool m_added; |
| private bool m_added; |
| |
| |
| private float m_alpha = 1f; |
| private float m_alpha = 1f; |
| |
| |
| private MeshRenderer m_mr; |
| private MeshRenderer m_mr; |
| |
| |
| private MaterialPropertyBlock m_propertyBlock; |
| private MaterialPropertyBlock m_propertyBlock; |
| |
| |
| private static readonly List<Smoke> s_smoke = new List<Smoke>(); |
| private static readonly List<Smoke> s_smoke = new List<Smoke>(); |
| |
| |
| private static readonly int m_colorProp = Shader.PropertyToID("_Color"); |
| private static readonly int m_colorProp = Shader.PropertyToID("_Color"); |
| |
| |
| private static readonly int m_randomAngleProp = Shader.PropertyToID("_RandomAngle"); |
| private static readonly int m_randomAngleProp = Shader.PropertyToID("_RandomAngle"); |
| } |
| } |
| |
| |