SunShaftsEditor.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace UnityStandardAssets.ImageEffects
  5. {
  6. [CustomEditor (typeof(SunShafts))]
  7. class SunShaftsEditor : Editor
  8. {
  9. SerializedObject serObj;
  10. SerializedProperty sunTransform;
  11. SerializedProperty radialBlurIterations;
  12. SerializedProperty sunColor;
  13. SerializedProperty sunThreshold;
  14. SerializedProperty sunShaftBlurRadius;
  15. SerializedProperty sunShaftIntensity;
  16. SerializedProperty useDepthTexture;
  17. SerializedProperty resolution;
  18. SerializedProperty screenBlendMode;
  19. SerializedProperty maxRadius;
  20. void OnEnable () {
  21. serObj = new SerializedObject (target);
  22. screenBlendMode = serObj.FindProperty("screenBlendMode");
  23. sunTransform = serObj.FindProperty("sunTransform");
  24. sunColor = serObj.FindProperty("sunColor");
  25. sunThreshold = serObj.FindProperty("sunThreshold");
  26. sunShaftBlurRadius = serObj.FindProperty("sunShaftBlurRadius");
  27. radialBlurIterations = serObj.FindProperty("radialBlurIterations");
  28. sunShaftIntensity = serObj.FindProperty("sunShaftIntensity");
  29. resolution = serObj.FindProperty("resolution");
  30. maxRadius = serObj.FindProperty("maxRadius");
  31. useDepthTexture = serObj.FindProperty("useDepthTexture");
  32. }
  33. public override void OnInspectorGUI () {
  34. serObj.Update ();
  35. EditorGUILayout.BeginHorizontal();
  36. EditorGUILayout.PropertyField (useDepthTexture, new GUIContent ("Rely on Z Buffer?"));
  37. if ((target as SunShafts).GetComponent<Camera>())
  38. GUILayout.Label("Current camera mode: "+ (target as SunShafts).GetComponent<Camera>().depthTextureMode, EditorStyles.miniBoldLabel);
  39. EditorGUILayout.EndHorizontal();
  40. // depth buffer need
  41. /*
  42. bool newVal = useDepthTexture.boolValue;
  43. if (newVal != oldVal) {
  44. if (newVal)
  45. (target as SunShafts).camera.depthTextureMode |= DepthTextureMode.Depth;
  46. else
  47. (target as SunShafts).camera.depthTextureMode &= ~DepthTextureMode.Depth;
  48. }
  49. */
  50. EditorGUILayout.PropertyField (resolution, new GUIContent("Resolution"));
  51. EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend mode"));
  52. EditorGUILayout.Separator ();
  53. EditorGUILayout.BeginHorizontal();
  54. EditorGUILayout.PropertyField (sunTransform, new GUIContent("Shafts caster", "Chose a transform that acts as a root point for the produced sun shafts"));
  55. if ((target as SunShafts).sunTransform && (target as SunShafts).GetComponent<Camera>()) {
  56. if (GUILayout.Button("Center on " + (target as SunShafts).GetComponent<Camera>().name)) {
  57. if (EditorUtility.DisplayDialog ("Move sun shafts source?", "The SunShafts caster named "+ (target as SunShafts).sunTransform.name +"\n will be centered along "+(target as SunShafts).GetComponent<Camera>().name+". Are you sure? ", "Please do", "Don't")) {
  58. Ray ray = (target as SunShafts).GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f,0.5f,0));
  59. (target as SunShafts).sunTransform.position = ray.origin + ray.direction * 500.0f;
  60. (target as SunShafts).sunTransform.LookAt ((target as SunShafts).transform);
  61. }
  62. }
  63. }
  64. EditorGUILayout.EndHorizontal();
  65. EditorGUILayout.Separator ();
  66. EditorGUILayout.PropertyField (sunThreshold, new GUIContent ("Threshold color"));
  67. EditorGUILayout.PropertyField (sunColor, new GUIContent ("Shafts color"));
  68. maxRadius.floatValue = 1.0f - EditorGUILayout.Slider ("Distance falloff", 1.0f - maxRadius.floatValue, 0.1f, 1.0f);
  69. EditorGUILayout.Separator ();
  70. sunShaftBlurRadius.floatValue = EditorGUILayout.Slider ("Blur size", sunShaftBlurRadius.floatValue, 1.0f, 10.0f);
  71. radialBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", radialBlurIterations.intValue, 1, 3);
  72. EditorGUILayout.Separator ();
  73. EditorGUILayout.PropertyField (sunShaftIntensity, new GUIContent("Intensity"));
  74. serObj.ApplyModifiedProperties();
  75. }
  76. }
  77. }