BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / AudioManager / Scripts / Audio / Editor / SoundFXRefPropertyDrawer.cs

SoundFXRefPropertyDrawer.cs

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