﻿using UnityEditor;

namespace Onward.CustomContent.Assets
{
    [CustomEditor(typeof(OnwardCustomAudioSource))]
    public class OnwardCustomAudioSourceEditor : Editor
    {
        private SerializedProperty audioSourceType;
        private SerializedProperty audioClipToPlay;
        private SerializedProperty normalizeClipVolume;
        private SerializedProperty volume;
        private SerializedProperty loop;
        private SerializedProperty attenuationType;
        private SerializedProperty outdoornessType;

        private void OnEnable()
        {
            audioSourceType = serializedObject.FindProperty("AudioSourceType");
            audioClipToPlay = serializedObject.FindProperty("AudioClipToPlay");
            normalizeClipVolume = serializedObject.FindProperty("NormalizeClipVolume");
            volume = serializedObject.FindProperty("Volume");
            loop = serializedObject.FindProperty("Loop");
            attenuationType = serializedObject.FindProperty("AttenuationType");
            outdoornessType = serializedObject.FindProperty("OutdoornessType");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(audioSourceType, new UnityEngine.GUIContent("Audio Source Type", "- Global Ambiences are heard throughout the entire level.\n- Local Ambiences are heard only when within the attenuation distance."));
            EditorGUILayout.PropertyField(audioClipToPlay, new UnityEngine.GUIContent("Audio Clip To Play", "Audio file to play. Accepts any Unity supported audio file type.\nRecommended Formats:\n- .ogg to reduce file size at the cost of cpu.\n- .wav at the cost of file size."));
            EditorGUILayout.PropertyField(normalizeClipVolume, new UnityEngine.GUIContent("Nomalize Clip Volume", "Change audio clip max volume to a common level. Helps make quiet audio louder."));
            EditorGUILayout.PropertyField(volume, new UnityEngine.GUIContent("Volume", "How loud the audio is."));
            EditorGUILayout.PropertyField(loop, new UnityEngine.GUIContent("Loop", "If the audio should loop after it finishes playing."));
            switch (audioSourceType.intValue)
            {
                case (int)OnwardAudioType.LocalAmbience:
                    EditorGUILayout.PropertyField(attenuationType, new UnityEngine.GUIContent("Attenuation Distance", "The distance at which the audio can no longer be heard. Louder the closer you are to the sound and quieter the further away you are from it."));
                    break;
                case (int)OnwardAudioType.GlobalAmbience:
                    EditorGUILayout.PropertyField(outdoornessType, new UnityEngine.GUIContent("When Audio is Played", "- Indoors and Outdoors does not reduce this audio's volume when in inside or outside area reverbs.\n- Indoors only mutes this audio when in an outside area reverb.\n- Outdoors only reduces volume of this audio when in an inside area reverb."));
                    break; 
            }
            serializedObject.ApplyModifiedProperties();
        }
    }
}
