Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created September 6, 2017 14:32
Show Gist options
  • Save unity3dcollege/5fb1ecbe78b8316f0b501d45b05e7e60 to your computer and use it in GitHub Desktop.
Save unity3dcollege/5fb1ecbe78b8316f0b501d45b05e7e60 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(SimpleAudioEvent), true)]
public class AudioEventEditor : Editor
{
[SerializeField] private AudioSource _previewer;
public void OnEnable()
{
_previewer = EditorUtility.CreateGameObjectWithHideFlags("Audio preview", HideFlags.HideAndDontSave, typeof(AudioSource)).GetComponent<AudioSource>();
}
public void OnDisable()
{
DestroyImmediate(_previewer.gameObject);
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
if (GUILayout.Button("Preview"))
{
((SimpleAudioEvent)target).Play(_previewer);
}
EditorGUI.EndDisabledGroup();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment