EdgeDetectionEditor.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace UnityStandardAssets.ImageEffects
  5. {
  6. [CustomEditor (typeof(EdgeDetection))]
  7. class EdgeDetectionEditor : Editor
  8. {
  9. SerializedObject serObj;
  10. SerializedProperty mode;
  11. SerializedProperty sensitivityDepth;
  12. SerializedProperty sensitivityNormals;
  13. SerializedProperty lumThreshold;
  14. SerializedProperty edgesOnly;
  15. SerializedProperty edgesOnlyBgColor;
  16. SerializedProperty edgeExp;
  17. SerializedProperty sampleDist;
  18. void OnEnable () {
  19. serObj = new SerializedObject (target);
  20. mode = serObj.FindProperty("mode");
  21. sensitivityDepth = serObj.FindProperty("sensitivityDepth");
  22. sensitivityNormals = serObj.FindProperty("sensitivityNormals");
  23. lumThreshold = serObj.FindProperty("lumThreshold");
  24. edgesOnly = serObj.FindProperty("edgesOnly");
  25. edgesOnlyBgColor = serObj.FindProperty("edgesOnlyBgColor");
  26. edgeExp = serObj.FindProperty("edgeExp");
  27. sampleDist = serObj.FindProperty("sampleDist");
  28. }
  29. public override void OnInspectorGUI () {
  30. serObj.Update ();
  31. GUILayout.Label("Detects spatial differences and converts into black outlines", EditorStyles.miniBoldLabel);
  32. EditorGUILayout.PropertyField (mode, new GUIContent("Mode"));
  33. if (mode.intValue < 2) {
  34. EditorGUILayout.PropertyField (sensitivityDepth, new GUIContent(" Depth Sensitivity"));
  35. EditorGUILayout.PropertyField (sensitivityNormals, new GUIContent(" Normals Sensitivity"));
  36. }
  37. else if (mode.intValue < 4) {
  38. EditorGUILayout.PropertyField (edgeExp, new GUIContent(" Edge Exponent"));
  39. }
  40. else {
  41. // lum based mode
  42. EditorGUILayout.PropertyField (lumThreshold, new GUIContent(" Luminance Threshold"));
  43. }
  44. EditorGUILayout.PropertyField (sampleDist, new GUIContent(" Sample Distance"));
  45. EditorGUILayout.Separator ();
  46. GUILayout.Label ("Background Options");
  47. edgesOnly.floatValue = EditorGUILayout.Slider (" Edges only", edgesOnly.floatValue, 0.0f, 1.0f);
  48. EditorGUILayout.PropertyField (edgesOnlyBgColor, new GUIContent (" Color"));
  49. serObj.ApplyModifiedProperties();
  50. }
  51. }
  52. }