SpecularLightingEditor.cs 1.9 KB

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