DetonatorSmoke.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. [AddComponentMenu("Detonator/Smoke")]
  5. public class DetonatorSmoke : DetonatorComponent
  6. {
  7. public override void Init()
  8. {
  9. this.FillMaterials(false);
  10. this.BuildSmokeA();
  11. this.BuildSmokeB();
  12. }
  13. public void FillMaterials(bool wipe)
  14. {
  15. if (!this.smokeAMaterial || wipe)
  16. {
  17. this.smokeAMaterial = base.MyDetonator().smokeAMaterial;
  18. }
  19. if (!this.smokeBMaterial || wipe)
  20. {
  21. this.smokeBMaterial = base.MyDetonator().smokeBMaterial;
  22. }
  23. }
  24. public void BuildSmokeA()
  25. {
  26. this._smokeA = new GameObject("SmokeA");
  27. this._smokeAEmitter = this._smokeA.AddComponent<DetonatorBurstEmitter>();
  28. this._smokeA.transform.parent = base.transform;
  29. this._smokeA.transform.localPosition = this.localPosition;
  30. this._smokeA.transform.localRotation = Quaternion.identity;
  31. this._smokeAEmitter.material = this.smokeAMaterial;
  32. this._smokeAEmitter.exponentialGrowth = false;
  33. this._smokeAEmitter.sizeGrow = 0.095f;
  34. this._smokeAEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  35. this._smokeAEmitter.upwardsBias = base.MyDetonator().upwardsBias;
  36. }
  37. public void UpdateSmokeA()
  38. {
  39. this._smokeA.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  40. this._smokeA.transform.LookAt(Camera.main.transform);
  41. this._smokeA.transform.localPosition = -(Vector3.forward * -1.5f);
  42. this._smokeAEmitter.color = this.color;
  43. this._smokeAEmitter.duration = this.duration * 0.5f;
  44. this._smokeAEmitter.durationVariation = 0f;
  45. this._smokeAEmitter.timeScale = this.timeScale;
  46. this._smokeAEmitter.count = 4f;
  47. this._smokeAEmitter.particleSize = 25f;
  48. this._smokeAEmitter.sizeVariation = 3f;
  49. this._smokeAEmitter.velocity = this.velocity;
  50. this._smokeAEmitter.startRadius = 10f;
  51. this._smokeAEmitter.size = this.size;
  52. this._smokeAEmitter.useExplicitColorAnimation = true;
  53. this._smokeAEmitter.explodeDelayMin = this.explodeDelayMin;
  54. this._smokeAEmitter.explodeDelayMax = this.explodeDelayMax;
  55. Color color = new Color(0.2f, 0.2f, 0.2f, 0.4f);
  56. Color color2 = new Color(0.2f, 0.2f, 0.2f, 0.7f);
  57. Color color3 = new Color(0.2f, 0.2f, 0.2f, 0.4f);
  58. Color color4 = new Color(0.2f, 0.2f, 0.2f, 0f);
  59. this._smokeAEmitter.colorAnimation[0] = color;
  60. this._smokeAEmitter.colorAnimation[1] = color2;
  61. this._smokeAEmitter.colorAnimation[2] = color2;
  62. this._smokeAEmitter.colorAnimation[3] = color3;
  63. this._smokeAEmitter.colorAnimation[4] = color4;
  64. }
  65. public void BuildSmokeB()
  66. {
  67. this._smokeB = new GameObject("SmokeB");
  68. this._smokeBEmitter = this._smokeB.AddComponent<DetonatorBurstEmitter>();
  69. this._smokeB.transform.parent = base.transform;
  70. this._smokeB.transform.localPosition = this.localPosition;
  71. this._smokeB.transform.localRotation = Quaternion.identity;
  72. this._smokeBEmitter.material = this.smokeBMaterial;
  73. this._smokeBEmitter.exponentialGrowth = false;
  74. this._smokeBEmitter.sizeGrow = 0.095f;
  75. this._smokeBEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  76. this._smokeBEmitter.upwardsBias = base.MyDetonator().upwardsBias;
  77. }
  78. public void UpdateSmokeB()
  79. {
  80. this._smokeB.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  81. this._smokeB.transform.LookAt(Camera.main.transform);
  82. this._smokeB.transform.localPosition = -(Vector3.forward * -1f);
  83. this._smokeBEmitter.color = this.color;
  84. this._smokeBEmitter.duration = this.duration * 0.5f;
  85. this._smokeBEmitter.durationVariation = 0f;
  86. this._smokeBEmitter.count = 2f;
  87. this._smokeBEmitter.particleSize = 25f;
  88. this._smokeBEmitter.sizeVariation = 3f;
  89. this._smokeBEmitter.velocity = this.velocity;
  90. this._smokeBEmitter.startRadius = 10f;
  91. this._smokeBEmitter.size = this.size;
  92. this._smokeBEmitter.useExplicitColorAnimation = true;
  93. this._smokeBEmitter.explodeDelayMin = this.explodeDelayMin;
  94. this._smokeBEmitter.explodeDelayMax = this.explodeDelayMax;
  95. Color color = new Color(0.2f, 0.2f, 0.2f, 0.4f);
  96. Color color2 = new Color(0.2f, 0.2f, 0.2f, 0.7f);
  97. Color color3 = new Color(0.2f, 0.2f, 0.2f, 0.4f);
  98. Color color4 = new Color(0.2f, 0.2f, 0.2f, 0f);
  99. this._smokeBEmitter.colorAnimation[0] = color;
  100. this._smokeBEmitter.colorAnimation[1] = color2;
  101. this._smokeBEmitter.colorAnimation[2] = color2;
  102. this._smokeBEmitter.colorAnimation[3] = color3;
  103. this._smokeBEmitter.colorAnimation[4] = color4;
  104. }
  105. public void Reset()
  106. {
  107. this.FillMaterials(true);
  108. this.on = true;
  109. this.size = 1f;
  110. this.duration = 8f;
  111. this.explodeDelayMin = 0f;
  112. this.explodeDelayMax = 0f;
  113. this.color = this._baseColor;
  114. this.velocity = new Vector3(3f, 3f, 3f);
  115. }
  116. public override void Explode()
  117. {
  118. if (this.detailThreshold > this.detail)
  119. {
  120. return;
  121. }
  122. if (this.on)
  123. {
  124. this.UpdateSmokeA();
  125. this.UpdateSmokeB();
  126. if (this.drawSmokeA)
  127. {
  128. this._smokeAEmitter.Explode();
  129. }
  130. if (this.drawSmokeB)
  131. {
  132. this._smokeBEmitter.Explode();
  133. }
  134. }
  135. }
  136. private const float _baseSize = 1f;
  137. private const float _baseDuration = 8f;
  138. private Color _baseColor = new Color(0.5f, 0.5f, 0.5f, 0.5f);
  139. private const float _baseDamping = 0.1300004f;
  140. private float _scaledDuration;
  141. private GameObject _smokeA;
  142. private DetonatorBurstEmitter _smokeAEmitter;
  143. public Material smokeAMaterial;
  144. private GameObject _smokeB;
  145. private DetonatorBurstEmitter _smokeBEmitter;
  146. public Material smokeBMaterial;
  147. public bool drawSmokeA = true;
  148. public bool drawSmokeB = true;
  149. }