Code Review

1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof(ColorCorrectionLookup))]
8     
class ColorCorrectionLookupEditor : Editor
9     {
10         SerializedObject serObj;
11
12         
void OnEnable () {
13             serObj =
new SerializedObject (target);
14         }
15
16         
private Texture2D tempClutTex2D;
17
18
19         
public override void OnInspectorGUI () {
20             serObj.Update ();
21
22             EditorGUILayout.LabelField(
"Converts textures into color lookup volumes (for grading)", EditorStyles.miniLabel);
23
24             
//EditorGUILayout.LabelField("Change Lookup Texture (LUT):");
25             
//EditorGUILayout.BeginHorizontal ();
26             
//Rect r = GUILayoutUtility.GetAspectRect(1.0ff);
27
28             Rect r; Texture2D t;
29
30             
//EditorGUILayout.Space();
31             tempClutTex2D = EditorGUILayout.ObjectField (
" Based on", tempClutTex2D, typeof(Texture2D), false) as Texture2D;
32             
if (tempClutTex2D == null) {
33                 t = AssetDatabase.LoadMainAssetAtPath(((ColorCorrectionLookup)target).basedOnTempTex)
as Texture2D;
34                 
if (t) tempClutTex2D = t;
35             }
36
37             Texture2D tex = tempClutTex2D;
38
39             
if (tex && (target as ColorCorrectionLookup).basedOnTempTex != AssetDatabase.GetAssetPath(tex))
40             {
41                 EditorGUILayout.Separator();
42                 
if (!(target as ColorCorrectionLookup).ValidDimensions(tex))
43                 {
44                     EditorGUILayout.HelpBox (
"Invalid texture dimensions!\nPick another texture or adjust dimension to e.g. 256x16.", MessageType.Warning);
45                 }
46                 
else if (GUILayout.Button ("Convert and Apply"))
47                 {
48                     
string path = AssetDatabase.GetAssetPath (tex);
49                     TextureImporter textureImporter = AssetImporter.GetAtPath(path)
as TextureImporter;
50                     
bool doImport = textureImporter.isReadable == false;
51                     
if (textureImporter.mipmapEnabled == true) {
52                         doImport =
true;
53                     }
54                     
if (textureImporter.textureFormat != TextureImporterFormat.AutomaticTruecolor) {
55                         doImport =
true;
56                     }
57
58                     
if (doImport)
59                     {
60                         textureImporter.isReadable =
true;
61                         textureImporter.mipmapEnabled =
false;
62                         textureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
63                         AssetDatabase.ImportAsset (path, ImportAssetOptions.ForceUpdate);
64                         
//tex = AssetDatabase.LoadMainAssetAtPath(path);
65                     }
66
67                     (target
as ColorCorrectionLookup).Convert(tex, path);
68                 }
69             }
70
71             
if ((target as ColorCorrectionLookup).basedOnTempTex != "")
72             {
73                 EditorGUILayout.HelpBox(
"Using " + (target as ColorCorrectionLookup).basedOnTempTex, MessageType.Info);
74                 t = AssetDatabase.LoadMainAssetAtPath(((ColorCorrectionLookup)target).basedOnTempTex)
as Texture2D;
75                 
if (t) {
76                     r = GUILayoutUtility.GetLastRect();
77                     r = GUILayoutUtility.GetRect(r.width,
20);
78                     r.x += r.width *
0.05f/2.0f;
79                     r.width *=
0.95f;
80                     GUI.DrawTexture (r, t);
81                     GUILayoutUtility.GetRect(r.width,
4);
82                 }
83             }
84
85             
//EditorGUILayout.EndHorizontal ();
86
87             serObj.ApplyModifiedProperties();
88         }
89     }
90 }


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 *