• BloomEditor.cs
  • /
  • /
  • /
  • /
1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof(Bloom))]
8     
class BloomEditor : Editor
9     {
10         SerializedProperty tweakMode;
11         SerializedProperty screenBlendMode;
12
13         SerializedObject serObj;
14
15         SerializedProperty hdr;
16         SerializedProperty quality;
17         SerializedProperty sepBlurSpread;
18
19         SerializedProperty bloomIntensity;
20         SerializedProperty bloomThresholdColor;
21         SerializedProperty bloomThreshold;
22         SerializedProperty bloomBlurIterations;
23
24         SerializedProperty hollywoodFlareBlurIterations;
25
26         SerializedProperty lensflareMode;
27         SerializedProperty hollyStretchWidth;
28         SerializedProperty lensflareIntensity;
29         SerializedProperty flareRotation;
30         SerializedProperty lensFlareSaturation;
31         SerializedProperty lensflareThreshold;
32         SerializedProperty flareColorA;
33         SerializedProperty flareColorB;
34         SerializedProperty flareColorC;
35         SerializedProperty flareColorD;
36
37         SerializedProperty lensFlareVignetteMask;
38
39         
void OnEnable () {
40             serObj =
new SerializedObject (target);
41
42             screenBlendMode = serObj.FindProperty(
"screenBlendMode");
43             hdr = serObj.FindProperty(
"hdr");
44             quality = serObj.FindProperty(
"quality");
45
46             sepBlurSpread = serObj.FindProperty(
"sepBlurSpread");
47
48             bloomIntensity = serObj.FindProperty(
"bloomIntensity");
49             bloomThreshold = serObj.FindProperty(
"bloomThreshold");
50             bloomThresholdColor = serObj.FindProperty(
"bloomThresholdColor");
51             bloomBlurIterations = serObj.FindProperty(
"bloomBlurIterations");
52
53             lensflareMode = serObj.FindProperty(
"lensflareMode");
54             hollywoodFlareBlurIterations = serObj.FindProperty(
"hollywoodFlareBlurIterations");
55             hollyStretchWidth = serObj.FindProperty(
"hollyStretchWidth");
56             lensflareIntensity = serObj.FindProperty(
"lensflareIntensity");
57             lensflareThreshold = serObj.FindProperty(
"lensflareThreshold");
58             lensFlareSaturation = serObj.FindProperty(
"lensFlareSaturation");
59             flareRotation = serObj.FindProperty(
"flareRotation");
60             flareColorA = serObj.FindProperty(
"flareColorA");
61             flareColorB = serObj.FindProperty(
"flareColorB");
62             flareColorC = serObj.FindProperty(
"flareColorC");
63             flareColorD = serObj.FindProperty(
"flareColorD");
64             lensFlareVignetteMask = serObj.FindProperty(
"lensFlareVignetteMask");
65
66             tweakMode = serObj.FindProperty(
"tweakMode");
67         }
68
69
70         
public override void OnInspectorGUI () {
71             serObj.Update();
72
73             EditorGUILayout.LabelField(
"Glow and Lens Flares for bright screen pixels", EditorStyles.miniLabel);
74
75             EditorGUILayout.PropertyField (quality,
new GUIContent("Quality", "High quality preserves high frequencies with bigger blurs and uses a better blending and down-/upsampling"));
76
77             EditorGUILayout.Separator ();
78
79             EditorGUILayout.PropertyField (tweakMode,
new GUIContent("Mode"));
80             EditorGUILayout.PropertyField (screenBlendMode,
new GUIContent("Blend"));
81             EditorGUILayout.PropertyField (hdr,
new GUIContent("HDR"));
82
83             EditorGUILayout.Separator ();
84
85             
// display info text when screen blend mode cannot be used
86             Camera cam = (target
as Bloom).GetComponent<Camera>();
87             
if (cam != null) {
88                 
if (screenBlendMode.enumValueIndex==0 && ((cam.hdr && hdr.enumValueIndex==0) || (hdr.enumValueIndex==1))) {
89                     EditorGUILayout.HelpBox(
"Screen blend is not supported in HDR. Using 'Add' instead.", MessageType.Info);
90                 }
91             }
92
93             EditorGUILayout.PropertyField (bloomIntensity,
new GUIContent("Intensity"));
94             bloomThreshold.floatValue = EditorGUILayout.Slider (
"Threshold", bloomThreshold.floatValue, -0.05f, 4.0f);
95             
if (1 == tweakMode.intValue) {
96                 EditorGUILayout.PropertyField(bloomThresholdColor,
new GUIContent(" RGB Threshold"));
97             }
98             EditorGUILayout.Separator ();
99
100             bloomBlurIterations.intValue = EditorGUILayout.IntSlider (
"Blur Iterations", bloomBlurIterations.intValue, 1, 4);
101             sepBlurSpread.floatValue = EditorGUILayout.Slider (
" Sample Distance", sepBlurSpread.floatValue, 0.1f, 10.0f);
102             EditorGUILayout.Separator ();
103
104             
if (1 == tweakMode.intValue) {
105                 
// further lens flare tweakings
106                 
if (0 != tweakMode.intValue)
107                     EditorGUILayout.PropertyField (lensflareMode,
new GUIContent("Lens Flares"));
108                 
else
109                     lensflareMode.enumValueIndex =
0;
110
111                 EditorGUILayout.PropertyField (lensflareIntensity,
new GUIContent(" Local Intensity", "0 disables lens flares entirely (optimization)"));
112                 lensflareThreshold.floatValue = EditorGUILayout.Slider (
"Threshold", lensflareThreshold.floatValue, 0.0f, 4.0f);
113
114                 
if (Mathf.Abs(lensflareIntensity.floatValue) > Mathf.Epsilon) {
115                     
if (lensflareMode.intValue == 0) {
116                         
// ghosting
117                         EditorGUILayout.BeginHorizontal ();
118                         EditorGUILayout.PropertyField (flareColorA,
new GUIContent(" 1st Color"));
119                         EditorGUILayout.PropertyField (flareColorB,
new GUIContent(" 2nd Color"));
120                         EditorGUILayout.EndHorizontal ();
121
122                         EditorGUILayout.BeginHorizontal ();
123                         EditorGUILayout.PropertyField (flareColorC,
new GUIContent(" 3rd Color"));
124                         EditorGUILayout.PropertyField (flareColorD,
new GUIContent(" 4th Color"));
125                         EditorGUILayout.EndHorizontal ();
126                     }
127                     
else if (lensflareMode.intValue == 1) {
128                         
// hollywood
129                         EditorGUILayout.PropertyField (hollyStretchWidth,
new GUIContent(" Stretch width"));
130                         EditorGUILayout.PropertyField (flareRotation,
new GUIContent( " Rotation"));
131                         hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider (
" Blur Iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
132
133                         EditorGUILayout.PropertyField (lensFlareSaturation,
new GUIContent(" Saturation"));
134                         EditorGUILayout.PropertyField (flareColorA,
new GUIContent(" Tint Color"));
135                     }
136                     
else if (lensflareMode.intValue == 2) {
137                         
// both
138                         EditorGUILayout.PropertyField (hollyStretchWidth,
new GUIContent(" Stretch width"));
139                         hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider (
" Blur Iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
140
141                         EditorGUILayout.PropertyField (lensFlareSaturation,
new GUIContent(" Saturation"));
142
143                         EditorGUILayout.BeginHorizontal ();
144                         EditorGUILayout.PropertyField (flareColorA,
new GUIContent(" 1st Color"));
145                         EditorGUILayout.PropertyField (flareColorB,
new GUIContent(" 2nd Color"));
146                         EditorGUILayout.EndHorizontal ();
147
148                         EditorGUILayout.BeginHorizontal ();
149                         EditorGUILayout.PropertyField (flareColorC,
new GUIContent(" 3rd Color"));
150                         EditorGUILayout.PropertyField (flareColorD,
new GUIContent(" 4th Color"));
151                         EditorGUILayout.EndHorizontal ();
152                     }
153
154                     EditorGUILayout.PropertyField(lensFlareVignetteMask,
new GUIContent(" Mask", "This mask is needed to prevent lens flare artifacts"));
155
156                 }
157             }
158
159             serObj.ApplyModifiedProperties();
160         }
161     }
162 }


Gõ tìm kiếm nhanh...