123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using UnityEngine;
- [RequireComponent(typeof(Detonator))]
- [AddComponentMenu("Detonator/Heatwave (Pro Only)")]
- public class DetonatorHeatwave : DetonatorComponent
- {
- public override void Init()
- {
- }
- private void Update()
- {
- if (this._delayedExplosionStarted)
- {
- this._explodeDelay -= Time.deltaTime;
- if (this._explodeDelay <= 0f)
- {
- this.Explode();
- }
- }
- if (this._heatwave)
- {
- this._heatwave.transform.rotation = Quaternion.FromToRotation(Vector3.up, Camera.main.transform.position - this._heatwave.transform.position);
- this._heatwave.transform.localPosition = this.localPosition + Vector3.forward * this.zOffset;
- this._elapsedTime += Time.deltaTime;
- this._normalizedTime = this._elapsedTime / this.duration;
- this.s = Mathf.Lerp(this._startSize, this._maxSize, this._normalizedTime);
- this._heatwave.GetComponent<Renderer>().material.SetFloat("_BumpAmt", (1f - this._normalizedTime) * this.distortion);
- this._heatwave.gameObject.transform.localScale = new Vector3(this.s, this.s, this.s);
- if (this._elapsedTime > this.duration)
- {
- UnityEngine.Object.Destroy(this._heatwave.gameObject);
- }
- }
- }
- public override void Explode()
- {
- if (SystemInfo.supportsImageEffects)
- {
- if (this.detailThreshold > this.detail || !this.on)
- {
- return;
- }
- if (!this._delayedExplosionStarted)
- {
- this._explodeDelay = this.explodeDelayMin + UnityEngine.Random.value * (this.explodeDelayMax - this.explodeDelayMin);
- }
- if (this._explodeDelay <= 0f)
- {
- this._startSize = 0f;
- this._maxSize = this.size * 10f;
- this._material = new Material(Shader.Find("HeatDistort"));
- this._heatwave = GameObject.CreatePrimitive(PrimitiveType.Plane);
- this._heatwave.name = "Heatwave";
- this._heatwave.transform.parent = base.transform;
- UnityEngine.Object.Destroy(this._heatwave.GetComponent(typeof(MeshCollider)));
- if (!this.heatwaveMaterial)
- {
- this.heatwaveMaterial = base.MyDetonator().heatwaveMaterial;
- }
- this._material.CopyPropertiesFromMaterial(this.heatwaveMaterial);
- this._heatwave.GetComponent<Renderer>().material = this._material;
- this._heatwave.transform.parent = base.transform;
- this._delayedExplosionStarted = false;
- this._explodeDelay = 0f;
- }
- else
- {
- this._delayedExplosionStarted = true;
- }
- }
- }
- public void Reset()
- {
- this.duration = this._baseDuration;
- }
- private GameObject _heatwave;
- private float s;
- private float _startSize;
- private float _maxSize;
- private float _baseDuration = 0.25f;
- private bool _delayedExplosionStarted;
- private float _explodeDelay;
- public float zOffset = 0.5f;
- public float distortion = 64f;
- private float _elapsedTime;
- private float _normalizedTime;
- public Material heatwaveMaterial;
- private Material _material;
- }
|