SoundFXRefPropertyDrawer.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace OVR
  5. {
  6. /*
  7. -----------------------
  8. SoundFXRefPropertyDrawer
  9. -----------------------
  10. */
  11. [CustomPropertyDrawer(typeof(SoundFXRef))]
  12. public class SoundFXRefPropertyDrawer : PropertyDrawer {
  13. static private GUIStyle disabledStyle = null;
  14. /*
  15. -----------------------
  16. OnGUI()
  17. -----------------------
  18. */
  19. public override void OnGUI( Rect position, SerializedProperty prop, GUIContent label ) {
  20. int idx = 0;
  21. Rect buttonPosition = position;
  22. buttonPosition.x = position.x + position.width - 40f;
  23. buttonPosition.width = 20f;
  24. position.width = buttonPosition.x - position.x - 2f;
  25. SerializedProperty nameProp = prop.FindPropertyRelative( "soundFXName" );
  26. if ( AudioManager.GetGameObject() == null ) {
  27. if ( disabledStyle == null ) {
  28. disabledStyle = new GUIStyle();
  29. disabledStyle.normal.textColor = Color.gray;
  30. }
  31. EditorGUI.LabelField(position, label.text, nameProp.stringValue, disabledStyle );
  32. }
  33. else {
  34. string[] soundFXNames = AudioManager.GetSoundFXNames( nameProp.stringValue, out idx );
  35. idx = EditorGUI.Popup( position, label.text, idx, soundFXNames );
  36. nameProp.stringValue = AudioManager.NameMinusGroup( soundFXNames[idx] );
  37. // play button
  38. if ( GUI.Button( buttonPosition, "\u25BA" ) ) {
  39. if ( AudioManager.IsSoundPlaying( nameProp.stringValue ) ) {
  40. AudioManager.StopSound( nameProp.stringValue );
  41. } else {
  42. AudioManager.PlaySound( nameProp.stringValue );
  43. }
  44. }
  45. buttonPosition.x += 22.0f;
  46. // select audio manager
  47. if ( GUI.Button( buttonPosition, "\u2630" ) ) {
  48. Selection.activeGameObject = AudioManager.GetGameObject();
  49. }
  50. }
  51. }
  52. }
  53. } // namespace OVR