Code Review

1 using UnityEngine;
2 using
System.Collections;
3
4 [RequireComponent (
typeof (Detonator))]
5 [AddComponentMenu(
"Detonator/Glow")]
6 public
class DetonatorGlow : DetonatorComponent
7 {
8     
private float _baseSize = 1f;
9     
private float _baseDuration = 1f;
10     
private Vector3 _baseVelocity = new Vector3(0f, 0f, 0f);
11     
private Color _baseColor = Color.black;
12     
private float _scaledDuration;
13     
14     
private GameObject _glow;
15     
private DetonatorBurstEmitter _glowEmitter;
16     
public Material glowMaterial;
17         
18     
override public void Init()
19     {
20         
//make sure there are materials at all
21         FillMaterials(
false);
22         BuildGlow();
23     }
24     
25     
//if materials are empty fill them with defaults
26     
public void FillMaterials(bool wipe)
27     {
28         
if (!glowMaterial || wipe)
29         {
30             glowMaterial = MyDetonator().glowMaterial;
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 BuildGlow()
37     {
38         _glow =
new GameObject("Glow");
39         _glowEmitter = (DetonatorBurstEmitter)_glow.AddComponent<DetonatorBurstEmitter>();
40         _glow.transform.parent =
this.transform;
41         _glow.transform.localPosition = localPosition;
42         _glowEmitter.material = glowMaterial;
43         _glowEmitter.exponentialGrowth =
false;
44         _glowEmitter.useExplicitColorAnimation =
true;
45         _glowEmitter.useWorldSpace = MyDetonator().useWorldSpace;
46         
47     }
48     
49     
public void UpdateGlow()
50     {
51         
//this needs
52         _glow.transform.localPosition = Vector3.Scale(localPosition,(
new Vector3(size, size, size)));
53         
54         _glowEmitter.color = color;
55         _glowEmitter.duration = duration;
56         _glowEmitter.timeScale = timeScale;
57         _glowEmitter.count =
1;
58         _glowEmitter.particleSize =
65f;
59         _glowEmitter.randomRotation =
false;
60         _glowEmitter.sizeVariation =
0f;
61         _glowEmitter.velocity =
new Vector3(0f, 0f, 0f);
62         _glowEmitter.startRadius =
0f;
63         _glowEmitter.sizeGrow =
0;
64         _glowEmitter.size = size;
65         _glowEmitter.explodeDelayMin = explodeDelayMin;
66         _glowEmitter.explodeDelayMax = explodeDelayMax;
67
68         Color stage1 = Color.Lerp(color, (
new Color(.5f, .1f, .1f, 1f)),.5f);
69         stage1.a = .
9f;
70         
71         Color stage2 = Color.Lerp(color, (
new Color(.6f, .3f, .3f, 1f)),.5f);
72         stage2.a = .
8f;
73         
74         Color stage3 = Color.Lerp(color, (
new Color(.7f, .3f, .3f, 1f)),.5f);
75         stage3.a = .
5f;
76         
77         Color stage4 = Color.Lerp(color, (
new Color(.4f, .3f, .4f, 1f)),.5f);
78         stage4.a = .
2f;
79         
80         Color stage5 =
new Color(.1f, .1f, .4f, 0f);
81         
82         _glowEmitter.colorAnimation[
0] = stage1;
83         _glowEmitter.colorAnimation[
1] = stage2;
84         _glowEmitter.colorAnimation[
2] = stage3;
85         _glowEmitter.colorAnimation[
3] = stage4;
86         _glowEmitter.colorAnimation[
4] = stage5;
87     }
88
89     
void Update ()
90     {
91         
//others might be able to do this too... only update themselves before exploding?
92     }
93
94     
public void Reset()
95     {
96         FillMaterials(
true);
97         
on = true;
98         size = _baseSize;
99         duration = _baseDuration;
100         explodeDelayMin =
0f;
101         explodeDelayMax =
0f;
102         color = _baseColor;
103         velocity = _baseVelocity;
104
105     }
106
107     
override public void Explode()
108     {
109         
if (detailThreshold > detail) return;
110         
111         
if (on)
112         {
113             UpdateGlow();
114             _glowEmitter.Explode();
115         }
116     }
117
118 }


Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *



Code gần giống!

Quản lý chương trình xử lý ảnh C#

Miễn phí
1

Phạm Tuấn Khang

Quản lý thư viện LINQ C#

Miễn phí
1

Phạm Tuấn Khang

Quản lý quán karaoke

Miễn phí
1

Phạm Tuấn Khang

Game xếp hình Tetris C#

Miễn phí
1

Phạm Tuấn Khang