using System; using UnityEngine; [RequireComponent(typeof(Detonator))] [AddComponentMenu("Detonator/Object Spray")] public class DetonatorSpray : DetonatorComponent { public override void Init() { } private void Update() { if (this._delayedExplosionStarted) { this._explodeDelay -= Time.deltaTime; if (this._explodeDelay <= 0f) { this.Explode(); } } } public override void Explode() { if (!this._delayedExplosionStarted) { this._explodeDelay = this.explodeDelayMin + UnityEngine.Random.value * (this.explodeDelayMax - this.explodeDelayMin); } if (this._explodeDelay <= 0f) { int num = (int)(this.detail * (float)this.count); for (int i = 0; i < num; i++) { Vector3 b = UnityEngine.Random.onUnitSphere * (this.startingRadius * this.size); Vector3 b2 = new Vector3(this.velocity.x * this.size, this.velocity.y * this.size, this.velocity.z * this.size); GameObject gameObject = UnityEngine.Object.Instantiate(this.sprayObject, base.transform.position + b, base.transform.rotation); gameObject.transform.parent = base.transform; this._tmpScale = this.minScale + UnityEngine.Random.value * (this.maxScale - this.minScale); this._tmpScale *= this.size; gameObject.transform.localScale = new Vector3(this._tmpScale, this._tmpScale, this._tmpScale); if (base.MyDetonator().upwardsBias > 0f) { b2 = new Vector3(b2.x / Mathf.Log(base.MyDetonator().upwardsBias), b2.y * Mathf.Log(base.MyDetonator().upwardsBias), b2.z / Mathf.Log(base.MyDetonator().upwardsBias)); } gameObject.GetComponent().velocity = Vector3.Scale(b.normalized, b2); gameObject.GetComponent().velocity = Vector3.Scale(b.normalized, b2); UnityEngine.Object.Destroy(gameObject, this.duration * this.timeScale); this._delayedExplosionStarted = false; this._explodeDelay = 0f; } } else { this._delayedExplosionStarted = true; } } public void Reset() { this.velocity = new Vector3(15f, 15f, 15f); } public GameObject sprayObject; public int count = 10; public float startingRadius; public float minScale = 1f; public float maxScale = 1f; private bool _delayedExplosionStarted; private float _explodeDelay; private Vector3 _explosionPosition; private float _tmpScale; }