using UnityEditor;
using UnityEngine;
namespace ActionGameFramework.Audio.Editor
{
///
/// Custom editor for that sorts sounds on the fly
///
[CustomEditor(typeof(HealthChangeAudioSource))]
public class HealthChangeAudioSourceEditor : UnityEditor.Editor
{
protected const string k_HelpMessage =
"This list needs to be sorted in order " +
"for sounds to be played correctly" +
"\nList will sort automatically when this component is deselected." +
"\nYou can also press the \'Sort\' button once you are done editing the sound list.";
///
/// The that is selected
///
protected HealthChangeAudioSource m_Source;
///
/// Sort the sounds when the is selected
///
protected void OnEnable()
{
m_Source = target as HealthChangeAudioSource;
}
///
/// Sort the sounds when is deselected
///
protected void OnDisable()
{
Sort();
}
///
/// Sort the 's sound list
///
protected void Sort()
{
if (m_Source != null)
{
m_Source.Sort();
EditorUtility.SetDirty(m_Source);
}
}
///
/// Provide a button to manually sort sounds that were edited
///
public override void OnInspectorGUI()
{
EditorGUILayout.HelpBox(k_HelpMessage, MessageType.Info);
base.OnInspectorGUI();
if (GUILayout.Button("Sort"))
{
Sort();
}
}
}
}