Example #1
0
        /// <summary>
        /// Returns a channeld idx to play a sound.
        /// Could be:
        /// 1. An empty channel (not yet used)
        /// 2. An IDLE channel
        /// 3. A busy channel but with less priority
        /// 4. A busy channel with the same priority
        ///
        /// If there isn't a channel that satisfy these conditions, returns -1
        ///
        /// </summary>
        /// <returns></returns>
        private int GetChannelIdx(SoundManagerClip smc)
        {
            for (int i = 0; i < channels; i++)
            {
                if (_fxASList[i].clip == null || !_fxASList[i].isPlaying)
                {
                    return(i);
                }
            }

            // No audiosource idle. Find a busy audiosource with less priority than the new one
            for (int i = 0; i < channels; i++)
            {
                if (_fxASList[i].clip != null && _listOfClipsInUse[i] != null && smc.priority > _listOfClipsInUse[i].priority)
                {
                    Debug.LogWarning("[SoundManager] Using a used channel with less priority.");
                    return(i);
                }
            }

            // Try something with the same priority
            for (int i = 0; i < channels; i++)
            {
                if (_fxASList[i].clip != null && _listOfClipsInUse[i] != null && smc.priority == _listOfClipsInUse[i].priority)
                {
                    Debug.LogWarning("[SoundManager] Using a used channel with the same priority.");
                    return(i);
                }
            }

            // Cannot find a suitable channel
            return(-1);
        }
Example #2
0
        /// <summary>
        /// Play the specified soundmanagerclip on the specified audiosource
        /// </summary>
        private void PlayThisSoundOnSource(int chnId, SoundManagerClip smc, Vector3 pos)
        {
            _fxASList[chnId].Stop();

            SetInfoOnAudioSource(chnId, smc, pos);

            _fxASList[chnId].Play();
        }
Example #3
0
 /// <summary>
 /// Copy the params from soundmanagerclip to the properties of the audiosource
 /// </summary>
 private void SetInfoOnAudioSource(int chnId, SoundManagerClip smc, Vector3 pos)
 {
     _fxASList[chnId].clip                  = smc.clip;
     _fxASList[chnId].loop                  = smc.loop;
     _fxASList[chnId].volume                = smc.volume;
     _fxASList[chnId].pitch                 = smc.pitch;
     _fxASList[chnId].panStereo             = smc.stereoPan;
     _fxASList[chnId].outputAudioMixerGroup = smc.mixerGroup;
     _fxASList[chnId].transform.position    = pos;
 }