You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

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