HKI Core
SoundClipEditor.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
3 
4 namespace HKI.Core.Audio.Editor
5 {
9  [CanEditMultipleObjects]
10  [CustomEditor(typeof(SoundClip))]
11  public class SoundClipEditor : UnityEditor.Editor
12  {
13  // Private variables
14  const string clipSPName = "Clip";
15  const string volumeSPName = "Volume";
16  const string pitchSPName = "Pitch";
17 
18  SerializedProperty clipSP = null;
19  SerializedProperty volumeSP = null;
20  SerializedProperty pitchSP = null;
21 
22  // OnEnable function
23  void OnEnable()
24  {
25  clipSP = serializedObject.FindProperty(clipSPName);
26  volumeSP = serializedObject.FindProperty(volumeSPName);
27  pitchSP = serializedObject.FindProperty(pitchSPName);
28  }
29 
30  // OnDisable
31  void OnDisable()
32  {
34  }
35 
36  // OnInspectorGUI function
37  public override void OnInspectorGUI()
38  {
39  serializedObject.Update();
40 
41  EditorGUILayout.LabelField("General Variables", EditorStyles.boldLabel);
42 
43  EditorGUILayout.BeginHorizontal();
44  EditorGUI.BeginChangeCheck();
45  EditorGUILayout.PropertyField(clipSP);
46  if(EditorGUI.EndChangeCheck())
48 
49  GUI.enabled = clipSP.objectReferenceValue != null;
50  if(PublicAudioUtil.IsClipPlaying((AudioClip)clipSP.objectReferenceValue))
51  {
52  if (GUILayout.Button("Stop", GUILayout.Width(50.0f)))
54  }
55  else
56  {
57  if (GUILayout.Button("Play", GUILayout.Width(50.0f)))
58  PublicAudioUtil.PlayClip((AudioClip)clipSP.objectReferenceValue);
59  }
60  GUI.enabled = true;
61  EditorGUILayout.EndHorizontal();
62 
63  EditorGUILayout.PropertyField(volumeSP);
64  EditorGUILayout.PropertyField(pitchSP);
65  serializedObject.ApplyModifiedProperties();
66  }
67 
68  }
69 }
static void PlayClip(AudioClip clip)
This class provides the capability to listen into audio clips in the editor.
static bool IsClipPlaying(AudioClip clip)
Custom inspector for the SoundClip class.