1 using UnityEngine;
2 using
System.Collections;
3
4 [RequireComponent (
typeof (Detonator))]
5 [AddComponentMenu(
"Detonator/Shockwave")]
6 public
class DetonatorShockwave : DetonatorComponent
7 {
8     
private float _baseSize = 1f;
9     
private float _baseDuration = .25f;
10     
private Vector3 _baseVelocity = new Vector3(0f, 0f, 0f);
11     
private Color _baseColor = Color.white;
12
13     
private GameObject _shockwave;
14     
private DetonatorBurstEmitter _shockwaveEmitter;
15     
public Material shockwaveMaterial;
16     
17     
public ParticleRenderMode renderMode;
18         
19     
override public void Init()
20     {
21         
//make sure there are materials at all
22         FillMaterials(
false);
23         BuildShockwave();
24     }
25     
26     
//if materials are empty fill them with defaults
27     
public void FillMaterials(bool wipe)
28     {
29         
if (!shockwaveMaterial || wipe)
30         {
31             shockwaveMaterial = MyDetonator().shockwaveMaterial;
32         }
33     }
34     
35     
//Build these to look correct at the stock Detonator size of 10m... then let the size parameter
36     
//cascade through to the emitters and let them do the scaling work... keep these absolute.
37     
public void BuildShockwave()
38     {
39         _shockwave =
new GameObject("Shockwave");
40         _shockwaveEmitter = (DetonatorBurstEmitter)_shockwave.AddComponent<DetonatorBurstEmitter>();
41         _shockwave.transform.parent =
this.transform;
42         _shockwave.transform.localRotation = Quaternion.identity;
43         _shockwave.transform.localPosition = localPosition;
44         _shockwaveEmitter.material = shockwaveMaterial;
45         _shockwaveEmitter.exponentialGrowth =
false;
46         _shockwaveEmitter.useWorldSpace = MyDetonator().useWorldSpace;
47     }
48     
49     
public void UpdateShockwave()
50     {
51         _shockwave.transform.localPosition = Vector3.Scale(localPosition,(
new Vector3(size, size, size)));
52         _shockwaveEmitter.color = color;
53         _shockwaveEmitter.duration = duration;
54         _shockwaveEmitter.durationVariation = duration *
0.1f;
55         _shockwaveEmitter.count =
1;
56         _shockwaveEmitter.detail =
1;
57         _shockwaveEmitter.particleSize =
25f;
58         _shockwaveEmitter.sizeVariation =
0f;
59         _shockwaveEmitter.velocity =
new Vector3(0f, 0f, 0f);
60         _shockwaveEmitter.startRadius =
0f;
61         _shockwaveEmitter.sizeGrow =
202f;
62         _shockwaveEmitter.size = size;
63         _shockwaveEmitter.explodeDelayMin = explodeDelayMin;
64         _shockwaveEmitter.explodeDelayMax = explodeDelayMax;
65         _shockwaveEmitter.renderMode = renderMode;
66     }
67
68     
public void Reset()
69     {
70         FillMaterials(
true);
71         
on = true;
72         size = _baseSize;
73         duration = _baseDuration;
74         explodeDelayMin =
0f;
75         explodeDelayMax =
0f;
76         color = _baseColor;
77         velocity = _baseVelocity;
78     }
79
80     
override public void Explode()
81     {
82         
if (on)
83         {
84             UpdateShockwave();
85             _shockwaveEmitter.Explode();
86         }
87     }
88
89 }


Tìm kết quả nhanh