Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. [CustomEditor(typeof(SpecularLighting))]
  5. public class SpecularLightingEditor : Editor
  6. {
  7. private SerializedObject serObj;
  8. private SerializedProperty specularLight;
  9.  
  10. public void OnEnable () {
  11. serObj = new SerializedObject (target);
  12. specularLight = serObj.FindProperty("specularLight");
  13. }
  14.  
  15. public override void OnInspectorGUI ()
  16. {
  17. serObj.Update();
  18.  
  19. GameObject go = ((SpecularLighting)serObj.targetObject).gameObject;
  20. WaterBase wb = (WaterBase)go.GetComponent(typeof(WaterBase));
  21.  
  22. if(!wb.sharedMaterial)
  23. return;
  24.  
  25. if(wb.sharedMaterial.HasProperty("_WorldLightDir")) {
  26. GUILayout.Label ("Transform casting specular highlights", EditorStyles.miniBoldLabel);
  27. EditorGUILayout.PropertyField(specularLight, new GUIContent("Specular light"));
  28.  
  29. if(wb.sharedMaterial.HasProperty("_SpecularColor"))
  30. WaterEditorUtility.SetMaterialColor(
  31. "_SpecularColor",
  32. EditorGUILayout.ColorField("Specular",
  33. WaterEditorUtility.GetMaterialColor("_SpecularColor", wb.sharedMaterial)),
  34. wb.sharedMaterial);
  35. if(wb.sharedMaterial.HasProperty("_Shininess"))
  36. WaterEditorUtility.SetMaterialFloat("_Shininess", EditorGUILayout.Slider(
  37. "Specular power",
  38. WaterEditorUtility.GetMaterialFloat("_Shininess", wb.sharedMaterial),
  39. 0.0F, 500.0F), wb.sharedMaterial);
  40. }
  41. else
  42. GUILayout.Label ("The shader doesn't have the needed _WorldLightDir property.", EditorStyles.miniBoldLabel);
  43.  
  44. serObj.ApplyModifiedProperties();
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement