Created
September 6, 2017 14:32
-
-
Save unity3dcollege/5fb1ecbe78b8316f0b501d45b05e7e60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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