Exemplo n.º 1
0
        /// <summary>
        /// Fade out the specified channel
        /// </summary>
        public void FadeOutSound(int chnId, float inSecs, SoundManagerCallback cbFn = null)
        {
            var fas = new FadeAudioSource
            {
                initialTime   = Time.realtimeSinceStartup,
                accumTime     = 0,
                fadeInSecs    = inSecs,
                targetVolume  = 0,
                audioSrc      = _fxASList[chnId],
                initialVolume = _fxASList[chnId].volume,
                fnCb          = cbFn
            };

            _listFaders.Add(fas);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fade in sound
        /// </summary>
        public int FadeInSound(Vector3 pos, string sndId, float inSecs, SoundManagerCallback cbFn = null)
        {
            Debug.Assert(_soundManagerClips.ContainsKey(sndId));
            var smc = _soundManagerClips[sndId];

            var chnId = GetChannelIdx(smc);

            if (chnId != -1)
            {
                var audSrc = _fxASList[chnId];

                // Stop the audiosource, just in case
                audSrc.Stop();

                // Set info on audiosource
                SetInfoOnAudioSource(chnId, smc, pos);

                // Set the volume to zero
                audSrc.volume = 0f;

                // Start play with volume 0
                audSrc.Play();

                var fas = new FadeAudioSource
                {
                    targetVolume  = smc.volume,
                    initialVolume = 0f,
                    fadeInSecs    = inSecs,
                    initialTime   = Time.realtimeSinceStartup,
                    accumTime     = 0f,
                    audioSrc      = audSrc,
                    fnCb          = cbFn
                };

                // Add the fader to the list
                _listFaders.Add(fas);

                return(chnId);
            }
            else
            {
                Debug.LogWarningFormat("[SoundManager] All audiosource are busy. Cannot play sound {0}", smc.name);
            }

            return(-1);
        }