Code Review

1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof( NoiseAndGrain))]
8     
class NoiseAndGrainEditor : Editor
9     {
10         SerializedObject serObj;
11
12         SerializedProperty intensityMultiplier;
13         SerializedProperty generalIntensity;
14         SerializedProperty blackIntensity;
15         SerializedProperty whiteIntensity;
16         SerializedProperty midGrey;
17
18         SerializedProperty dx11Grain;
19         SerializedProperty softness;
20         SerializedProperty monochrome;
21
22         SerializedProperty intensities;
23         SerializedProperty tiling;
24         SerializedProperty monochromeTiling;
25
26         SerializedProperty noiseTexture;
27         SerializedProperty filterMode;
28
29         
void OnEnable () {
30             serObj =
new SerializedObject (target);
31
32             intensityMultiplier = serObj.FindProperty(
"intensityMultiplier");
33             generalIntensity = serObj.FindProperty(
"generalIntensity");
34             blackIntensity = serObj.FindProperty(
"blackIntensity");
35             whiteIntensity = serObj.FindProperty(
"whiteIntensity");
36             midGrey = serObj.FindProperty(
"midGrey");
37
38             dx11Grain = serObj.FindProperty(
"dx11Grain");
39             softness = serObj.FindProperty(
"softness");
40             monochrome = serObj.FindProperty(
"monochrome");
41
42             intensities = serObj.FindProperty(
"intensities");
43             tiling = serObj.FindProperty(
"tiling");
44             monochromeTiling = serObj.FindProperty(
"monochromeTiling");
45
46             noiseTexture = serObj.FindProperty(
"noiseTexture");
47             filterMode = serObj.FindProperty(
"filterMode");
48         }
49
50
51         
public override void OnInspectorGUI () {
52             serObj.Update();
53
54             EditorGUILayout.LabelField(
"Overlays animated noise patterns", EditorStyles.miniLabel);
55
56             EditorGUILayout.PropertyField(dx11Grain,
new GUIContent("DirectX 11 Grain"));
57
58             
if (dx11Grain.boolValue && !(target as NoiseAndGrain).Dx11Support()) {
59                 EditorGUILayout.HelpBox(
"DX11 mode not supported (need DX11 GPU and enable DX11 in PlayerSettings)", MessageType.Info);
60             }
61
62             EditorGUILayout.PropertyField(monochrome,
new GUIContent("Monochrome"));
63
64             EditorGUILayout.Separator();
65
66             EditorGUILayout.Slider(intensityMultiplier,
0.0f, 10.0f, new GUIContent("Intensity Multiplier"));
67             EditorGUILayout.Slider(generalIntensity,
0.0f, 1.0f, new GUIContent(" General"));
68             EditorGUILayout.Slider(blackIntensity,
0.0f, 1.0f, new GUIContent(" Black Boost"));
69             EditorGUILayout.Slider(whiteIntensity,
0.0f, 1.0f, new GUIContent(" White Boost"));
70             midGrey.floatValue = EditorGUILayout.Slider(
new GUIContent(" Mid Grey (for Boost)"), midGrey.floatValue, 0.0f, 1.0f);
71             
if (monochrome.boolValue == false) {
72                 Color c =
new Color(intensities.vector3Value.x,intensities.vector3Value.y,intensities.vector3Value.z,1.0f);
73                 c = EditorGUILayout.ColorField(
new GUIContent(" Color Weights"), c);
74                 intensities.vector3Value =
new Vector3(c.r, c.g, c.b);
75             }
76
77             
if (!dx11Grain.boolValue) {
78                 EditorGUILayout.Separator();
79
80                 EditorGUILayout.LabelField(
"Noise Shape");
81                 EditorGUILayout.PropertyField(noiseTexture,
new GUIContent(" Texture"));
82                 EditorGUILayout.PropertyField(filterMode,
new GUIContent(" Filter"));
83             }
84             
else {
85                 EditorGUILayout.Separator();
86                 EditorGUILayout.LabelField(
"Noise Shape");
87             }
88
89             softness.floatValue = EditorGUILayout.Slider(
new GUIContent(" Softness"),softness.floatValue, 0.0f, 0.99f);
90
91             
if (!dx11Grain.boolValue) {
92                 EditorGUILayout.Separator();
93                 EditorGUILayout.LabelField(
"Advanced");
94
95                 
if (monochrome.boolValue == false)
96                 {
97                     Vector3 temp = tiling.vector3Value;
98                     temp.x = EditorGUILayout.FloatField(
new GUIContent(" Tiling (Red)"), tiling.vector3Value.x);
99                     temp.y = EditorGUILayout.FloatField(
new GUIContent(" Tiling (Green)"), tiling.vector3Value.y);
100                     temp.z = EditorGUILayout.FloatField(
new GUIContent(" Tiling (Blue)"), tiling.vector3Value.z);
101                     tiling.vector3Value = temp;
102                 }
103                 
else {
104                     EditorGUILayout.PropertyField(monochromeTiling,
new GUIContent(" Tiling"));
105                 }
106             }
107
108             serObj.ApplyModifiedProperties();
109         }
110     }
111 }


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 *