• SpecularLightingEditor.cs
  • /
  • /
  • /
  • /
  • /
1 using UnityEngine;
2 using
UnityEditor;
3
4 namespace
UnityStandardAssets.Water
5 {
6     
[CustomEditor(typeof(SpecularLighting))]
7     
public class SpecularLightingEditor : Editor
8     {
9         
private SerializedObject serObj;
10         
private SerializedProperty specularLight;
11
12         
public void OnEnable()
13         {
14             serObj =
new SerializedObject(target);
15             specularLight = serObj.FindProperty(
"specularLight");
16         }
17
18         
public override void OnInspectorGUI()
19         {
20             serObj.Update();
21
22             GameObject go = ((SpecularLighting)serObj.targetObject).gameObject;
23             WaterBase wb = (WaterBase)go.GetComponent(
typeof(WaterBase));
24
25             
if (!wb.sharedMaterial)
26                 
return;
27
28             
if (wb.sharedMaterial.HasProperty("_WorldLightDir"))
29             {
30                 GUILayout.Label(
"Transform casting specular highlights", EditorStyles.miniBoldLabel);
31                 EditorGUILayout.PropertyField(specularLight,
new GUIContent("Specular light"));
32
33                 
if (wb.sharedMaterial.HasProperty("_SpecularColor"))
34                     WaterEditorUtility.SetMaterialColor(
35                         
"_SpecularColor",
36                         EditorGUILayout.ColorField(
"Specular",
37                         WaterEditorUtility.GetMaterialColor(
"_SpecularColor", wb.sharedMaterial)),
38                         wb.sharedMaterial);
39                 
if (wb.sharedMaterial.HasProperty("_Shininess"))
40                     WaterEditorUtility.SetMaterialFloat(
"_Shininess", EditorGUILayout.Slider(
41                         
"Specular power",
42                         WaterEditorUtility.GetMaterialFloat(
"_Shininess", wb.sharedMaterial),
43                         
0.0F, 500.0F), wb.sharedMaterial);
44             }
45             
else
46                 GUILayout.Label(
"The shader doesn't have the needed _WorldLightDir property.", EditorStyles.miniBoldLabel);
47
48             serObj.ApplyModifiedProperties();
49         }
50
51     }
52 }


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