static void PlayButton(Rect r, DeAudioClipData value) { if (GUI.Button(r, "►", Styles.btPlay)) { DeEditorSoundUtils.StopAll(); if (value.clip != null) { DeEditorSoundUtils.Play(value.clip); } } }
void Play(SerializedProperty property) { AudioClip clip = property.FindPropertyRelative("clip").objectReferenceValue as AudioClip; if (clip == null) { return; } MonoBehaviour m = GetValidMonoBehaviour(property); if (m == null) { // Can't use AudioSource: play clip regardless of volume DeEditorSoundUtils.StopAll(); DeEditorSoundUtils.Play(clip); return; } AudioSource s = m.GetComponent <AudioSource>(); if (s == null) { if (EditorUtility.DisplayDialog("Play DeAudioClipData", "Add AudioSource to preview the clip with the correct volume?", "Ok", "Cancel")) { s = m.gameObject.AddComponent <AudioSource>(); } } if (s == null) { return; } s.playOnAwake = false; s.volume = property.FindPropertyRelative("volume").floatValue; s.pitch = property.FindPropertyRelative("pitch").floatValue; s.loop = property.FindPropertyRelative("loop").boolValue; s.clip = clip; s.Play(); }