SoundFXPropertyDrawer.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace OVR
  5. {
  6. /*
  7. -----------------------
  8. SoundFXPropertyDrawer
  9. -----------------------
  10. */
  11. [CustomPropertyDrawer(typeof(SoundFX))]
  12. public class SoundFXPropertyDrawer : PropertyDrawer {
  13. static float lineHeight = EditorGUIUtility.singleLineHeight + 2.0f;
  14. static string[] props = new string[] { "name", "playback", "volume", "pitchVariance", "falloffDistance", "falloffCurve", "reverbZoneMix", "spread", "pctChanceToPlay", "priority", "delay", "looping", "ospProps", "soundClips" };
  15. /*
  16. -----------------------
  17. OnGUI()
  18. -----------------------
  19. */
  20. public override void OnGUI( Rect position, SerializedProperty prop, GUIContent label ) {
  21. EditorGUILayout.BeginVertical();
  22. for ( int i = 0; i < props.Length; i++ ) {
  23. EditorGUI.indentLevel = 2;
  24. SerializedProperty property = prop.FindPropertyRelative( props[i] );
  25. if ( props[i] == "reverbZoneMix" ) {
  26. EditorGUILayout.BeginHorizontal();
  27. SerializedProperty reverbCurve = prop.FindPropertyRelative( "reverbZoneMix" );
  28. EditorGUILayout.PropertyField( reverbCurve, true, GUILayout.Width( Screen.width - 130.0f ) );
  29. if ( GUILayout.Button( "Reset", GUILayout.Width( 50.0f ) ) ) {
  30. reverbCurve.animationCurveValue = new AnimationCurve( new Keyframe[2] { new Keyframe( 0f, 1.0f ), new Keyframe( 1f, 1f ) } );
  31. }
  32. EditorGUILayout.EndHorizontal();
  33. } else {
  34. EditorGUILayout.PropertyField( property, true, GUILayout.Width( Screen.width - 80.0f ) );
  35. position.y += lineHeight + 4.0f;
  36. if ( props[i] == "falloffCurve" ) {
  37. if ( property.enumValueIndex == (int)AudioRolloffMode.Custom ) {
  38. EditorGUILayout.PropertyField( prop.FindPropertyRelative( "volumeFalloffCurve" ), true, GUILayout.Width( Screen.width - 80.0f ) );
  39. position.y += lineHeight + 4.0f;
  40. }
  41. }
  42. }
  43. }
  44. EditorGUILayout.EndVertical();
  45. GUILayout.Space( 5.0f );
  46. }
  47. /*
  48. -----------------------
  49. GetPropertyHeight()
  50. -----------------------
  51. */
  52. public override float GetPropertyHeight (SerializedProperty prop, GUIContent label) {
  53. return base.GetPropertyHeight( prop, label );
  54. }
  55. }
  56. } // namespace OVR