예제 #1
0
        public SFXManager()
        {
            _AudioChannelPool = new AudioChannelPool(AudioChannelLimit);
            _Libraries        = FindAudioLibraries();

            AudioLog.Assert(_Libraries.Length > 0, "No audiolibraries found in root resources folder");
        }
예제 #2
0
        public AudioManager()
        {
            _AudioChannelPool = new AudioChannelPool(AUDIO_CHANNEL_COUNT);
            _Libraries        = FindAudioLibraries();

            AudioLog.Assert(_Libraries.Length > 0, "No audiolibraries found in root resources folder");
        }
예제 #3
0
        public AudioChannelPool(int channelCount)
        {
            AudioLog.Assert(channelCount > 0, $"Invalid amount of audio channels provided: {channelCount}");

            _AudioChannels = new AudioChannel[channelCount];

            GameObject             parentObject      = new GameObject("Audio Channels");
            UnityCallbackBehaviour callbackBehaviour = parentObject.AddComponent <UnityCallbackBehaviour>();

            Object.DontDestroyOnLoad(parentObject);
            for (int i = 0; i < _AudioChannels.Length; i++)
            {
                _AudioChannels[i] = new AudioChannel(parentObject.transform, callbackBehaviour, i + 1);
            }
        }
예제 #4
0
        private AudioAsset ResolveAsset(AudioEvent audioEvent)
        {
            AudioAsset asset = null;

            for (int i = 0; i < _Libraries.Length; i++)
            {
                asset = _Libraries[i].Resolve(audioEvent.Identifier);
                if (asset)
                {
                    break;
                }
            }

            AudioLog.Assert(asset, $"{audioEvent.Identifier} could not be found in any audio library.");
            return(asset);
        }
예제 #5
0
        /// <summary>
        /// Will configure an audio source according to the settings in an AudioAsset
        /// </summary>
        public static void ConfigureAudioSource(AudioSource audioSource, AudioAsset asset)
        {
            if (asset.AudioClips == null || asset.ClipCount == 0)
            {
                AudioLog.Warning($"tried playing asset {asset.name} but it has no clips.");
                return;
            }

            float     pitch = asset.GetPitch();
            AudioClip clip  = asset.GetClip();

            if (clip == null)
            {
                AudioLog.Warning($"{asset.name} asset returned null as clip.");
                return;
            }

            audioSource.spatialBlend = asset.SpatialBlend;
            audioSource.dopplerLevel = asset.Doppler;

            audioSource.loop                  = asset.IsLooped;
            audioSource.panStereo             = asset.Pan;
            audioSource.outputAudioMixerGroup = asset.AudioMixerGroup;
            audioSource.pitch                 = pitch;
            audioSource.clip                  = clip;
            audioSource.volume                = asset.Volume;
            audioSource.maxDistance           = asset.MaxDistance;
            audioSource.minDistance           = asset.MinDistance;

            if (asset.RandomStartPosition)
            {
                audioSource.timeSamples = Random.Range(0, clip.samples - 1);
            }
            else
            {
                audioSource.timeSamples = pitch < 0 ? (clip.samples - 1) : 0;
            }
        }
예제 #6
0
        public static void ConfigureAudioSource(AudioSource audioSource, AudioAsset asset)
        {
            if (asset.ClipCount == 0)
            {
                AudioLog.Warning($"tried playing asset {asset.name} but it has no clips.");
                return;
            }

            float     pitch = asset.GetPitch();
            AudioClip clip  = asset.GetClip();

            if (clip == null)
            {
                AudioLog.Warning($"{asset.name} asset returned null as clip.");
                return;
            }

            audioSource.panStereo             = asset.Pan;
            audioSource.outputAudioMixerGroup = asset.AudioMixerGroup;
            audioSource.pitch       = pitch;
            audioSource.clip        = clip;
            audioSource.volume      = asset.Volume;
            audioSource.timeSamples = pitch < 0 ? (clip.samples - 1) : 0;            // reverse clip if we play backwards
        }