123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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<GameObject>(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<Rigidbody>().velocity = Vector3.Scale(b.normalized, b2);
- gameObject.GetComponent<Rigidbody>().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;
- }
|