public static AudioCaseCustom GetCustomSource(bool autoRelease, AudioType audioType = AudioType.Sound)
        {
            AudioSource source = null;

            if (!instance.customSources.IsNullOrEmpty())
            {
                source = instance.customSources[0];
                instance.customSources.RemoveAt(0);
            }
            else
            {
                source = instance.CreateAudioSourceObject(true);
            }

            SetSourceDefaultSettings(source, audioType);

            AudioCaseCustom audioCase = new AudioCaseCustom(null, source, AudioType.Sound, autoRelease);

            instance.activeCustomSourcesCases.Add(audioCase);

            return(audioCase);
        }
        public static void ReleaseCustomSource(AudioCaseCustom audioCase, float fadeTime = 0)
        {
            int streamID = instance.activeCustomSourcesCases.FindIndex(x => x.source == audioCase.source);

            if (streamID != -1)
            {
                if (fadeTime == 0)
                {
                    instance.activeCustomSourcesCases[streamID].source.Stop();
                    instance.activeCustomSourcesCases[streamID].source.clip = null;
                    instance.activeCustomSourcesCases.RemoveAt(streamID);
                    instance.customSources.Add(audioCase.source);
                }
                else
                {
                    instance.activeCustomSourcesCases[streamID].source.DOVolume(0f, fadeTime).OnComplete(() =>
                    {
                        instance.activeCustomSourcesCases.Remove(audioCase);
                        audioCase.source.Stop();
                        instance.customSources.Add(audioCase.source);
                    });
                }
            }
        }
 public static void StopStream(AudioCaseCustom audioCase, float fadeTime = 0)
 {
     ReleaseCustomSource(audioCase, fadeTime);
 }
Esempio n. 4
0
        private void OnClipLoaded(AudioClip audioClip)
        {
            customAudioCase = AudioController.GetCustomSource(false, audioType);

            customAudioCase.source.clip = audioClip;
        }