Code Review

1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof(DepthOfFieldDeprecated))]
8     
class DepthOfFieldDeprecatedEditor : Editor
9     {
10         SerializedObject serObj;
11
12         SerializedProperty simpleTweakMode;
13
14         SerializedProperty focalPoint;
15         SerializedProperty smoothness;
16
17         SerializedProperty focalSize;
18
19         SerializedProperty focalZDistance;
20         SerializedProperty focalStartCurve;
21         SerializedProperty focalEndCurve;
22
23         SerializedProperty visualizeCoc;
24
25         SerializedProperty resolution;
26         SerializedProperty quality;
27
28         SerializedProperty objectFocus;
29
30         SerializedProperty bokeh;
31         SerializedProperty bokehScale;
32         SerializedProperty bokehIntensity;
33         SerializedProperty bokehThresholdLuminance;
34         SerializedProperty bokehThresholdContrast;
35         SerializedProperty bokehDownsample;
36         SerializedProperty bokehTexture;
37         SerializedProperty bokehDestination;
38
39         SerializedProperty bluriness;
40         SerializedProperty maxBlurSpread;
41         SerializedProperty foregroundBlurExtrude;
42
43         
void OnEnable () {
44             serObj =
new SerializedObject (target);
45
46             simpleTweakMode = serObj.FindProperty (
"simpleTweakMode");
47
48             
// simple tweak mode
49             focalPoint = serObj.FindProperty (
"focalPoint");
50             smoothness = serObj.FindProperty (
"smoothness");
51
52             
// complex tweak mode
53             focalZDistance = serObj.FindProperty (
"focalZDistance");
54             focalStartCurve = serObj.FindProperty (
"focalZStartCurve");
55             focalEndCurve = serObj.FindProperty (
"focalZEndCurve");
56             focalSize = serObj.FindProperty (
"focalSize");
57
58             visualizeCoc = serObj.FindProperty (
"visualize");
59
60             objectFocus = serObj.FindProperty (
"objectFocus");
61
62             resolution = serObj.FindProperty (
"resolution");
63             quality = serObj.FindProperty (
"quality");
64             bokehThresholdContrast = serObj.FindProperty (
"bokehThresholdContrast");
65             bokehThresholdLuminance = serObj.FindProperty (
"bokehThresholdLuminance");
66
67             bokeh = serObj.FindProperty (
"bokeh");
68             bokehScale = serObj.FindProperty (
"bokehScale");
69             bokehIntensity = serObj.FindProperty (
"bokehIntensity");
70             bokehDownsample = serObj.FindProperty (
"bokehDownsample");
71             bokehTexture = serObj.FindProperty (
"bokehTexture");
72             bokehDestination = serObj.FindProperty (
"bokehDestination");
73
74             bluriness = serObj.FindProperty (
"bluriness");
75             maxBlurSpread = serObj.FindProperty (
"maxBlurSpread");
76             foregroundBlurExtrude = serObj.FindProperty (
"foregroundBlurExtrude");
77         }
78
79
80         
public override void OnInspectorGUI () {
81             serObj.Update ();
82
83             GameObject go = (target
as DepthOfFieldDeprecated).gameObject;
84
85             
if (!go)
86                 
return;
87
88             
if (!go.GetComponent<Camera>())
89                 
return;
90
91             
if (simpleTweakMode.boolValue)
92                 GUILayout.Label (
"Current: "+go.GetComponent<Camera>().name+", near "+go.GetComponent<Camera>().nearClipPlane+", far: "+go.GetComponent<Camera>().farClipPlane+", focal: "+focalPoint.floatValue, EditorStyles.miniBoldLabel);
93             
else
94                 GUILayout.Label (
"Current: "+go.GetComponent<Camera>().name+", near "+go.GetComponent<Camera>().nearClipPlane+", far: "+go.GetComponent<Camera>().farClipPlane+", focal: "+focalZDistance.floatValue, EditorStyles.miniBoldLabel);
95
96             EditorGUILayout.PropertyField (resolution,
new GUIContent("Resolution"));
97             EditorGUILayout.PropertyField (quality,
new GUIContent("Quality"));
98
99             EditorGUILayout.PropertyField (simpleTweakMode,
new GUIContent("Simple tweak"));
100             EditorGUILayout.PropertyField (visualizeCoc,
new GUIContent("Visualize focus"));
101             EditorGUILayout.PropertyField (bokeh,
new GUIContent("Enable bokeh"));
102
103
104             EditorGUILayout.Separator ();
105
106             GUILayout.Label (
"Focal Settings", EditorStyles.boldLabel);
107
108             
if (simpleTweakMode.boolValue) {
109                 focalPoint.floatValue = EditorGUILayout.Slider (
"Focal distance", focalPoint.floatValue, go.GetComponent<Camera>().nearClipPlane, go.GetComponent<Camera>().farClipPlane);
110                 EditorGUILayout.PropertyField (objectFocus,
new GUIContent("Transform"));
111                 EditorGUILayout.PropertyField (smoothness,
new GUIContent("Smoothness"));
112                 focalSize.floatValue = EditorGUILayout.Slider (
"Focal size", focalSize.floatValue, 0.0f, (go.GetComponent<Camera>().farClipPlane - go.GetComponent<Camera>().nearClipPlane));
113             }
114             
else {
115                 focalZDistance.floatValue = EditorGUILayout.Slider (
"Distance", focalZDistance.floatValue, go.GetComponent<Camera>().nearClipPlane, go.GetComponent<Camera>().farClipPlane);
116                 EditorGUILayout.PropertyField (objectFocus,
new GUIContent("Transform"));
117                 focalSize.floatValue = EditorGUILayout.Slider (
"Size", focalSize.floatValue, 0.0f, (go.GetComponent<Camera>().farClipPlane - go.GetComponent<Camera>().nearClipPlane));
118                 focalStartCurve.floatValue = EditorGUILayout.Slider (
"Start curve", focalStartCurve.floatValue, 0.05f, 20.0f);
119                 focalEndCurve.floatValue = EditorGUILayout.Slider (
"End curve", focalEndCurve.floatValue, 0.05f, 20.0f);
120             }
121
122             EditorGUILayout.Separator ();
123
124             GUILayout.Label (
"Blur (Fore- and Background)", EditorStyles.boldLabel);
125             EditorGUILayout.PropertyField (bluriness,
new GUIContent("Blurriness"));
126             EditorGUILayout.PropertyField (maxBlurSpread,
new GUIContent("Blur spread"));
127
128             
if (quality.enumValueIndex > 0) {
129                 EditorGUILayout.PropertyField (foregroundBlurExtrude,
new GUIContent("Foreground size"));
130             }
131
132             EditorGUILayout.Separator ();
133
134             
if (bokeh.boolValue) {
135                 EditorGUILayout.Separator ();
136                 GUILayout.Label (
"Bokeh Settings", EditorStyles.boldLabel);
137                 EditorGUILayout.PropertyField (bokehDestination,
new GUIContent("Destination"));
138                 bokehIntensity.floatValue = EditorGUILayout.Slider (
"Intensity", bokehIntensity.floatValue, 0.0f, 1.0f);
139                 bokehThresholdLuminance.floatValue = EditorGUILayout.Slider (
"Min luminance", bokehThresholdLuminance.floatValue, 0.0f, 0.99f);
140                 bokehThresholdContrast.floatValue = EditorGUILayout.Slider (
"Min contrast", bokehThresholdContrast.floatValue, 0.0f, 0.25f);
141                 bokehDownsample.intValue = EditorGUILayout.IntSlider (
"Downsample", bokehDownsample.intValue, 1, 3);
142                 bokehScale.floatValue = EditorGUILayout.Slider (
"Size scale", bokehScale.floatValue, 0.0f, 20.0f);
143                 EditorGUILayout.PropertyField (bokehTexture ,
new GUIContent("Texture mask"));
144             }
145
146             serObj.ApplyModifiedProperties();
147         }
148     }
149 }


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