mirror of
https://github.com/ConjureETS/Unity_Utils.git
synced 2026-03-24 04:50:58 +00:00
37 lines
955 B
C#
37 lines
955 B
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace AudioEvent
|
|
{
|
|
[CustomEditor(typeof(AudioEvent), true)]
|
|
public class AudioEventInspector : Editor
|
|
{
|
|
[SerializeField] private AudioSource _audioSource;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_audioSource =
|
|
EditorUtility.CreateGameObjectWithHideFlags("Audio preview", HideFlags.HideAndDontSave,
|
|
typeof(AudioSource)).GetComponent<AudioSource>();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
DestroyImmediate(_audioSource.gameObject);
|
|
}
|
|
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
DrawDefaultInspector();
|
|
|
|
EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
|
|
if (GUILayout.Button("Preview"))
|
|
{
|
|
((AudioEvent) target).Play(_audioSource);
|
|
}
|
|
|
|
EditorGUI.EndDisabledGroup();
|
|
}
|
|
}
|
|
} |