DetonatorFireball.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. [AddComponentMenu("Detonator/Fireball")]
  5. public class DetonatorFireball : DetonatorComponent
  6. {
  7. public override void Init()
  8. {
  9. this.FillMaterials(false);
  10. this.BuildFireballA();
  11. this.BuildFireballB();
  12. this.BuildFireShadow();
  13. }
  14. public void FillMaterials(bool wipe)
  15. {
  16. if (!this.fireballAMaterial || wipe)
  17. {
  18. this.fireballAMaterial = base.MyDetonator().fireballAMaterial;
  19. }
  20. if (!this.fireballBMaterial || wipe)
  21. {
  22. this.fireballBMaterial = base.MyDetonator().fireballBMaterial;
  23. }
  24. if (!this.fireShadowMaterial || wipe)
  25. {
  26. if ((double)UnityEngine.Random.value > 0.5)
  27. {
  28. this.fireShadowMaterial = base.MyDetonator().smokeAMaterial;
  29. }
  30. else
  31. {
  32. this.fireShadowMaterial = base.MyDetonator().smokeBMaterial;
  33. }
  34. }
  35. }
  36. public void BuildFireballA()
  37. {
  38. this._fireballA = new GameObject("FireballA");
  39. this._fireballAEmitter = this._fireballA.AddComponent<DetonatorBurstEmitter>();
  40. this._fireballA.transform.parent = base.transform;
  41. this._fireballA.transform.localRotation = Quaternion.identity;
  42. this._fireballAEmitter.material = this.fireballAMaterial;
  43. this._fireballAEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  44. this._fireballAEmitter.upwardsBias = base.MyDetonator().upwardsBias;
  45. }
  46. public void UpdateFireballA()
  47. {
  48. this._fireballA.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  49. this._fireballAEmitter.color = this.color;
  50. this._fireballAEmitter.duration = this.duration * 0.5f;
  51. this._fireballAEmitter.durationVariation = this.duration * 0.5f;
  52. this._fireballAEmitter.count = 2f;
  53. this._fireballAEmitter.timeScale = this.timeScale;
  54. this._fireballAEmitter.detail = this.detail;
  55. this._fireballAEmitter.particleSize = 14f;
  56. this._fireballAEmitter.sizeVariation = 3f;
  57. this._fireballAEmitter.velocity = this.velocity;
  58. this._fireballAEmitter.startRadius = 4f;
  59. this._fireballAEmitter.size = this.size;
  60. this._fireballAEmitter.useExplicitColorAnimation = true;
  61. Color b = new Color(1f, 1f, 1f, 0.5f);
  62. Color b2 = new Color(0.6f, 0.15f, 0.15f, 0.3f);
  63. Color color = new Color(0.1f, 0.2f, 0.45f, 0f);
  64. this._fireballAEmitter.colorAnimation[0] = Color.Lerp(this.color, b, 0.8f);
  65. this._fireballAEmitter.colorAnimation[1] = Color.Lerp(this.color, b, 0.5f);
  66. this._fireballAEmitter.colorAnimation[2] = this.color;
  67. this._fireballAEmitter.colorAnimation[3] = Color.Lerp(this.color, b2, 0.7f);
  68. this._fireballAEmitter.colorAnimation[4] = color;
  69. this._fireballAEmitter.explodeDelayMin = this.explodeDelayMin;
  70. this._fireballAEmitter.explodeDelayMax = this.explodeDelayMax;
  71. }
  72. public void BuildFireballB()
  73. {
  74. this._fireballB = new GameObject("FireballB");
  75. this._fireballBEmitter = this._fireballB.AddComponent<DetonatorBurstEmitter>();
  76. this._fireballB.transform.parent = base.transform;
  77. this._fireballB.transform.localRotation = Quaternion.identity;
  78. this._fireballBEmitter.material = this.fireballBMaterial;
  79. this._fireballBEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  80. this._fireballBEmitter.upwardsBias = base.MyDetonator().upwardsBias;
  81. }
  82. public void UpdateFireballB()
  83. {
  84. this._fireballB.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  85. this._fireballBEmitter.color = this.color;
  86. this._fireballBEmitter.duration = this.duration * 0.5f;
  87. this._fireballBEmitter.durationVariation = this.duration * 0.5f;
  88. this._fireballBEmitter.count = 2f;
  89. this._fireballBEmitter.timeScale = this.timeScale;
  90. this._fireballBEmitter.detail = this.detail;
  91. this._fireballBEmitter.particleSize = 10f;
  92. this._fireballBEmitter.sizeVariation = 6f;
  93. this._fireballBEmitter.velocity = this.velocity;
  94. this._fireballBEmitter.startRadius = 4f;
  95. this._fireballBEmitter.size = this.size;
  96. this._fireballBEmitter.useExplicitColorAnimation = true;
  97. Color b = new Color(1f, 1f, 1f, 0.5f);
  98. Color b2 = new Color(0.6f, 0.15f, 0.15f, 0.3f);
  99. Color color = new Color(0.1f, 0.2f, 0.45f, 0f);
  100. this._fireballBEmitter.colorAnimation[0] = Color.Lerp(this.color, b, 0.8f);
  101. this._fireballBEmitter.colorAnimation[1] = Color.Lerp(this.color, b, 0.5f);
  102. this._fireballBEmitter.colorAnimation[2] = this.color;
  103. this._fireballBEmitter.colorAnimation[3] = Color.Lerp(this.color, b2, 0.7f);
  104. this._fireballBEmitter.colorAnimation[4] = color;
  105. this._fireballBEmitter.explodeDelayMin = this.explodeDelayMin;
  106. this._fireballBEmitter.explodeDelayMax = this.explodeDelayMax;
  107. }
  108. public void BuildFireShadow()
  109. {
  110. this._fireShadow = new GameObject("FireShadow");
  111. this._fireShadowEmitter = this._fireShadow.AddComponent<DetonatorBurstEmitter>();
  112. this._fireShadow.transform.parent = base.transform;
  113. this._fireShadow.transform.localRotation = Quaternion.identity;
  114. this._fireShadowEmitter.material = this.fireShadowMaterial;
  115. this._fireShadowEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  116. this._fireShadowEmitter.upwardsBias = base.MyDetonator().upwardsBias;
  117. }
  118. public void UpdateFireShadow()
  119. {
  120. this._fireShadow.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  121. this._fireShadow.transform.LookAt(Camera.main.transform);
  122. this._fireShadow.transform.localPosition = -(Vector3.forward * 1f);
  123. this._fireShadowEmitter.color = new Color(0.1f, 0.1f, 0.1f, 0.6f);
  124. this._fireShadowEmitter.duration = this.duration * 0.5f;
  125. this._fireShadowEmitter.durationVariation = this.duration * 0.5f;
  126. this._fireShadowEmitter.timeScale = this.timeScale;
  127. this._fireShadowEmitter.detail = 1f;
  128. this._fireShadowEmitter.particleSize = 13f;
  129. this._fireShadowEmitter.velocity = this.velocity;
  130. this._fireShadowEmitter.sizeVariation = 1f;
  131. this._fireShadowEmitter.count = 4f;
  132. this._fireShadowEmitter.startRadius = 6f;
  133. this._fireShadowEmitter.size = this.size;
  134. this._fireShadowEmitter.explodeDelayMin = this.explodeDelayMin;
  135. this._fireShadowEmitter.explodeDelayMax = this.explodeDelayMax;
  136. }
  137. public void Reset()
  138. {
  139. this.FillMaterials(true);
  140. this.on = true;
  141. this.size = this._baseSize;
  142. this.duration = this._baseDuration;
  143. this.explodeDelayMin = 0f;
  144. this.explodeDelayMax = 0f;
  145. this.color = this._baseColor;
  146. this.velocity = this._baseVelocity;
  147. }
  148. public override void Explode()
  149. {
  150. if (this.detailThreshold > this.detail)
  151. {
  152. return;
  153. }
  154. if (this.on)
  155. {
  156. this.UpdateFireballA();
  157. this.UpdateFireballB();
  158. this.UpdateFireShadow();
  159. if (this.drawFireballA)
  160. {
  161. this._fireballAEmitter.Explode();
  162. }
  163. if (this.drawFireballB)
  164. {
  165. this._fireballBEmitter.Explode();
  166. }
  167. if (this.drawFireShadow)
  168. {
  169. this._fireShadowEmitter.Explode();
  170. }
  171. }
  172. }
  173. private float _baseSize = 1f;
  174. private float _baseDuration = 3f;
  175. private Color _baseColor = new Color(1f, 0.423f, 0f, 0.5f);
  176. private Vector3 _baseVelocity = new Vector3(60f, 60f, 60f);
  177. private float _scaledDuration;
  178. private GameObject _fireballA;
  179. private DetonatorBurstEmitter _fireballAEmitter;
  180. public Material fireballAMaterial;
  181. private GameObject _fireballB;
  182. private DetonatorBurstEmitter _fireballBEmitter;
  183. public Material fireballBMaterial;
  184. private GameObject _fireShadow;
  185. private DetonatorBurstEmitter _fireShadowEmitter;
  186. public Material fireShadowMaterial;
  187. public bool drawFireballA = true;
  188. public bool drawFireballB = true;
  189. public bool drawFireShadow = true;
  190. private Color _detailAdjustedColor;
  191. }