1 using UnityEngine;
2 using
System.Collections;
3
4 // This one isn
't ready for prime time and is not in the menu. Feel free to modify or complete. :)
5 [RequireComponent (
typeof (Detonator))]
6 public
class DetonatorCloudRing : DetonatorComponent
7 {
8     
private float _baseSize = 1f;
9     
private float _baseDuration = 5f;
10     
private Vector3 _baseVelocity = new Vector3(155f, 5f, 155f);
11     
private Color _baseColor = Color.white;
12     
private Vector3 _baseForce = new Vector3(0.162f, 2.56f, 0f);
13     
14     
private GameObject _cloudRing;
15     
private DetonatorBurstEmitter _cloudRingEmitter;
16     
public Material cloudRingMaterial;
17     
18     
override public void Init()
19     {
20         
//make sure there are materials at all
21         FillMaterials(
false);
22         BuildCloudRing();
23     }
24     
25     
//if materials are empty fill them with defaults
26     
public void FillMaterials(bool wipe)
27     {
28         
if (!cloudRingMaterial || wipe)
29         {
30             cloudRingMaterial = MyDetonator().smokeBMaterial;
31         }
32     }
33
34     
//Build these to look correct at the stock Detonator size of 10m... then let the size parameter
35     
//cascade through to the emitters and let them do the scaling work... keep these absolute.
36     
public void BuildCloudRing()
37     {
38         _cloudRing =
new GameObject("CloudRing");
39         _cloudRingEmitter = (DetonatorBurstEmitter)_cloudRing.AddComponent<DetonatorBurstEmitter>();
40         _cloudRing.transform.parent =
this.transform;
41         _cloudRing.transform.localPosition = localPosition;
42         _cloudRingEmitter.material = cloudRingMaterial;
43         _cloudRingEmitter.useExplicitColorAnimation =
true;
44     }
45     
46     
public void UpdateCloudRing()
47     {
48         _cloudRing.transform.localPosition = Vector3.Scale(localPosition,(
new Vector3(size, size, size)));
49         
50         _cloudRingEmitter.color = color;
51         _cloudRingEmitter.duration = duration;
52         _cloudRingEmitter.durationVariation = duration/
4f;
53         _cloudRingEmitter.count = (
int)(detail * 50f);
54         _cloudRingEmitter.particleSize =
10f;
55         _cloudRingEmitter.sizeVariation =
2f;
56         _cloudRingEmitter.velocity = velocity;
57         _cloudRingEmitter.startRadius =
3f;
58         _cloudRingEmitter.size = size;
59         _cloudRingEmitter.force = force;
60         _cloudRingEmitter.explodeDelayMin = explodeDelayMin;
61         _cloudRingEmitter.explodeDelayMax = explodeDelayMax;
62         
63         
//make the starting colors more intense, towards white
64         Color color1 = Color.Lerp(color, (
new Color(.2f, .2f, .2f, .6f)), 0.5f);
65         Color color2 =
new Color(.2f, .2f, .2f, .5f);
66         Color color3 =
new Color(.2f, .2f, .2f, .3f);
67         Color color4 =
new Color(.2f, .2f, .2f, 0f);
68         
69         _cloudRingEmitter.colorAnimation[
0] = color1;
70         _cloudRingEmitter.colorAnimation[
1] = color2;
71         _cloudRingEmitter.colorAnimation[
2] = color2;
72         _cloudRingEmitter.colorAnimation[
3] = color3;
73         _cloudRingEmitter.colorAnimation[
4] = color4;
74     }
75
76     
public void Reset()
77     {
78         FillMaterials(
true);
79         
on = true;
80         size = _baseSize;
81         duration = _baseDuration;
82         explodeDelayMin =
0f;
83         explodeDelayMax =
0f;
84         color = _baseColor;
85         velocity = _baseVelocity;
86         force = _baseForce;
87     }
88
89     
override public void Explode()
90     {
91         
if (on)
92         {
93             UpdateCloudRing();
94             _cloudRingEmitter.Explode();
95         }
96     }
97
98 }


Tìm kết quả nhanh