OSPPropsPropertyDrawer.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace OVR
  5. {
  6. /*
  7. -----------------------
  8. OSPPropsPropertyDrawer
  9. -----------------------
  10. */
  11. [CustomPropertyDrawer(typeof(OSPProps))]
  12. public class OSPPropsPropertyDrawer : PropertyDrawer {
  13. static float lineHeight = EditorGUIUtility.singleLineHeight + 2.0f;
  14. static float indent = 32.0f;
  15. // TODO - some day just enumerate these
  16. static string[] props = new string[] { "useFastOverride", "gain", "enableInvSquare", "volumetric" , "invSquareFalloff" };
  17. static string[] names = new string[] { "Reflections Enabled", "Gain", "Enable Oculus Atten.", "Volumetric", "Range" };
  18. static int[] lines = new int[] { 1, 1, 1, 1, 2, 2 };
  19. /*
  20. -----------------------
  21. OnGUI()
  22. -----------------------
  23. */
  24. public override void OnGUI( Rect position, SerializedProperty prop, GUIContent label ) {
  25. SerializedProperty playSpatializedProp = prop.FindPropertyRelative("enableSpatialization");
  26. position.height = lineHeight;
  27. EditorGUI.PropertyField( position, playSpatializedProp );
  28. if ( playSpatializedProp.boolValue ) {
  29. position.y += lineHeight + 4.0f;
  30. Rect posLine = position;
  31. posLine.x += indent;
  32. posLine.width -= indent;
  33. posLine.height = 1f;
  34. GUI.Box( posLine, "" );
  35. position.y -= 10.0f;
  36. for ( int i = 0; i < props.Length; i++ ) {
  37. position.y += lineHeight;
  38. position.height = ( lineHeight * lines[i] );
  39. SerializedProperty sibling = prop.FindPropertyRelative( props[i] );
  40. EditorGUI.PropertyField( position, sibling, new GUIContent( names[i] ) );
  41. }
  42. }
  43. }
  44. /*
  45. -----------------------
  46. GetPropertyHeight()
  47. -----------------------
  48. */
  49. public override float GetPropertyHeight (SerializedProperty prop, GUIContent label) {
  50. SerializedProperty playSpatializedProp = prop.FindPropertyRelative("enableSpatialization");
  51. if ( !playSpatializedProp.boolValue ) {
  52. return base.GetPropertyHeight( prop, label );
  53. } else {
  54. return base.GetPropertyHeight( prop, label ) + ( lineHeight * ( props.Length + 1 ) ) + 16.0f;
  55. }
  56. }
  57. }
  58. } // namespace OVR