1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof(ColorCorrectionCurves))]
8     
class ColorCorrectionCurvesEditor : Editor {
9         SerializedObject serObj;
10
11         SerializedProperty mode;
12
13         SerializedProperty redChannel;
14         SerializedProperty greenChannel;
15         SerializedProperty blueChannel;
16
17         SerializedProperty useDepthCorrection;
18
19         SerializedProperty depthRedChannel;
20         SerializedProperty depthGreenChannel;
21         SerializedProperty depthBlueChannel;
22
23         SerializedProperty zCurveChannel;
24
25         SerializedProperty saturation;
26
27         SerializedProperty selectiveCc;
28         SerializedProperty selectiveFromColor;
29         SerializedProperty selectiveToColor;
30
31         
private bool applyCurveChanges = false;
32
33         
void OnEnable () {
34             serObj =
new SerializedObject (target);
35
36             mode = serObj.FindProperty (
"mode");
37
38             saturation = serObj.FindProperty (
"saturation");
39
40             redChannel = serObj.FindProperty (
"redChannel");
41             greenChannel = serObj.FindProperty (
"greenChannel");
42             blueChannel = serObj.FindProperty (
"blueChannel");
43
44             useDepthCorrection = serObj.FindProperty (
"useDepthCorrection");
45
46             zCurveChannel = serObj.FindProperty (
"zCurve");
47
48             depthRedChannel = serObj.FindProperty (
"depthRedChannel");
49             depthGreenChannel = serObj.FindProperty (
"depthGreenChannel");
50             depthBlueChannel = serObj.FindProperty (
"depthBlueChannel");
51
52             serObj.ApplyModifiedProperties ();
53
54             selectiveCc = serObj.FindProperty (
"selectiveCc");
55             selectiveFromColor = serObj.FindProperty (
"selectiveFromColor");
56             selectiveToColor = serObj.FindProperty (
"selectiveToColor");
57         }
58
59         
void CurveGui ( string name, SerializedProperty animationCurve, Color color) {
60             
// @NOTE: EditorGUILayout.CurveField is buggy and flickers, using PropertyField for now
61             
//animationCurve.animationCurveValue = EditorGUILayout.CurveField (GUIContent (name), animationCurve.animationCurveValue, color, Rect (0.0f,0.0f,1.0f,1.0f));
62             EditorGUILayout.PropertyField (animationCurve,
new GUIContent (name));
63             
if (GUI.changed)
64                 applyCurveChanges =
true;
65         }
66
67         
void BeginCurves () {
68             applyCurveChanges =
false;
69         }
70
71         
void ApplyCurves () {
72             
if (applyCurveChanges) {
73                 serObj.ApplyModifiedProperties ();
74                 (serObj.targetObject
as ColorCorrectionCurves).gameObject.SendMessage ("UpdateTextures");
75             }
76         }
77
78
79         
public override void OnInspectorGUI () {
80             serObj.Update ();
81
82             GUILayout.Label (
"Use curves to tweak RGB channel colors", EditorStyles.miniBoldLabel);
83
84             saturation.floatValue = EditorGUILayout.Slider(
"Saturation", saturation.floatValue, 0.0f, 5.0f);
85
86             EditorGUILayout.PropertyField (mode,
new GUIContent ("Mode"));
87             EditorGUILayout.Separator ();
88
89             BeginCurves ();
90
91             CurveGui (
" Red", redChannel, Color.red);
92             CurveGui (
" Green", greenChannel, Color.green);
93             CurveGui (
" Blue", blueChannel, Color.blue);
94
95             EditorGUILayout.Separator ();
96
97             
if (mode.intValue > 0)
98                 useDepthCorrection.boolValue =
true;
99             
else
100                 useDepthCorrection.boolValue =
false;
101
102             
if (useDepthCorrection.boolValue) {
103                 CurveGui (
" Red (depth)", depthRedChannel, Color.red);
104                 CurveGui (
" Green (depth)", depthGreenChannel, Color.green);
105                 CurveGui (
" Blue (depth)", depthBlueChannel, Color.blue);
106                 EditorGUILayout.Separator ();
107                 CurveGui (
" Blend Curve", zCurveChannel, Color.grey);
108             }
109
110             EditorGUILayout.Separator ();
111             EditorGUILayout.PropertyField (selectiveCc,
new GUIContent ("Selective"));
112             
if (selectiveCc.boolValue) {
113                 EditorGUILayout.PropertyField (selectiveFromColor,
new GUIContent (" Key"));
114                 EditorGUILayout.PropertyField (selectiveToColor,
new GUIContent (" Target"));
115             }
116
117
118             ApplyCurves ();
119
120             
if (!applyCurveChanges)
121                 serObj.ApplyModifiedProperties ();
122         }
123     }
124 }


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