public NamedClip playMusic(TMusicEnum music, float time = 0f, Action MusicEndedCallback = null, bool cancelCallbackOnInterrupt = true)
    {
        NamedClip namedClip = null;

        if (MusicDictionary.TryGetValue(music, out namedClip) && namedClip != null && namedClip.Clip != null)
        {
            MainAudioSource.Stop();
            MainAudioSource.clip   = namedClip.Clip;
            MainAudioSource.time   = time;
            MainAudioSource.volume = namedClip.volume;
            MainAudioSource.Play();
            currentMusic = music;

            if (MusicEndedCallback != null)
            {
                if (_MusicCallcabkCorutine != null)
                {
                    StopCoroutine(_MusicCallcabkCorutine);
                }

                _MusicCallcabkCorutine = MusicCallcabkCorutine(MusicEndedCallback, cancelCallbackOnInterrupt);
                StartCoroutine(_MusicCallcabkCorutine);
            }
        }

        return(namedClip);
    }
    private NamedClip playSound(TSoundsEnum sound, Action SoundEndedCallback = null)
    {
        NamedClip namedClip = null;

        if (SoundsDictionary.TryGetValue(sound, out namedClip) && namedClip != null && namedClip.Clip != null)
        {
            MainAudioSource.PlayOneShot(namedClip.Clip, namedClip.volume);

            if (SoundEndedCallback != null)
            {
                StartCoroutine(ClipCallcabkCorutine(namedClip.Clip.length, SoundEndedCallback));
            }
        }

        return(namedClip);
    }
    public SoundClip3D playSound3D(TSoundsEnum sound, Vector3 worldPos, float minDistance = 1f, float maxDistance = 100f, Action SoundEndedCallback = null)
    {
        NamedClip namedClip = null;

        if (SoundsDictionary.TryGetValue(sound, out namedClip) && namedClip != null && namedClip.Clip != null)
        {
            var newSoundClip3D = SoundClip3D.InstantiateAt(worldPos, namedClip.Clip, namedClip.volume, minDistance, maxDistance);

            if (SoundEndedCallback != null)
            {
                StartCoroutine(ClipCallcabkCorutine(namedClip.Clip.length, SoundEndedCallback));
            }

            return(newSoundClip3D);
        }

        return(null);
    }
    public void UpdateInspectorAndDictionaries()
    {
        //Update sounds list
        var soundNames = Enum.GetNames(typeof(TSoundsEnum));

        if (lastEnumCount_Sounds != soundNames.Length || lastListCount_Sounds != soundNames.Length)
        {
            SoundsDictionary.Clear();
            List <NamedClip> newSoundsList = new List <NamedClip>();
            foreach (var soundName in soundNames)
            {
                var newNamedClip = new NamedClip();
                newNamedClip.Name = soundName;

                if (SoundsList != null)
                {
                    //check if the clip already been set before, and move it to the new list
                    var oldNamedClip = SoundsList.FirstOrDefault(x => x.Name == soundName);
                    if (oldNamedClip != null)
                    {
                        newNamedClip.Clip   = oldNamedClip.Clip;
                        newNamedClip.volume = oldNamedClip.volume;
                    }
                }

                //add to dictionary
                TSoundsEnum value = (TSoundsEnum)Enum.Parse(typeof(TSoundsEnum), newNamedClip.Name);
                SoundsDictionary[value] = newNamedClip;

                newSoundsList.Add(newNamedClip);
            }
            SoundsList = newSoundsList.ToArray();
        }

        //Update music list
        var musicNames = Enum.GetNames(typeof(TMusicEnum));

        if (lastEnumCount_Music != musicNames.Length || lastListCount_Music != musicNames.Length)
        {
            MusicDictionary.Clear();
            List <NamedClip> newMusicList = new List <NamedClip>();
            foreach (var musicName in musicNames)
            {
                var newNamedClip = new NamedClip();
                newNamedClip.Name = musicName;

                if (MusicList != null)
                {
                    //check if the clip already been set before, and move it to the new list
                    var oldNamedClip = MusicList.FirstOrDefault(x => x.Name == musicName);
                    if (oldNamedClip != null)
                    {
                        newNamedClip.Clip   = oldNamedClip.Clip;
                        newNamedClip.volume = oldNamedClip.volume;
                    }
                }

                //add to dictionary
                TMusicEnum value = (TMusicEnum)Enum.Parse(typeof(TMusicEnum), newNamedClip.Name);
                MusicDictionary[value] = newNamedClip;

                newMusicList.Add(newNamedClip);
            }
            MusicList = newMusicList.ToArray();
        }

        //Set delay variables
        lastInspectorUpdate = DateTime.Now;
    }