Ejemplo n.º 1
0
        public void PlaySound(string audioClipName, WSound.PlayOptions options = null, Action onStopCallback = null)
        {
            if (audioClipName.IsEmpty())
            {
                return;
            }

            AudioClip clip = GetAudioClip(audioClipName);

            if (null != clip)
            {
                WSound soundFX = GetAvailableSound();
                if (null != soundFX)
                {
                    soundFX.PlaySound(_audioClips[audioClipName], options, onStopCallback);
                    AddToCurPlaying(soundFX);
                }
            }
            else
            {
                if (!audioClipName.IsEmpty())
                {
                    Print.Log(() => "yellow", $"sfx: {audioClipName} not found");
                }
            }
        }
Ejemplo n.º 2
0
        void AddToCurPlaying(WSound sound)
        {
            if (_currentPlaying.Exists(x => x.Same(sound)))
            {
                return;
            }

            _currentPlaying.Add(sound);
        }
Ejemplo n.º 3
0
        public WSound GetPlayingSound(string audioClipName)
        {
            for (int i = 0; i < _currentPlaying.Count; ++i)
            {
                WSound sound = _currentPlaying[i];
                if (sound.AudioName == audioClipName)
                {
                    return(sound);
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        public void InitAudioManager()
        {
            _sound = prefabSound.Clone <WSound>(transform);
            Assert.Null <WSound>(_sound);

            // on init, load all the sfx in the path defined
            AudioClip[] audioClipsFromResources = Resources.LoadAll <AudioClip>(path);
            for (int i = 0; i < audioClipsFromResources.Length; ++i)
            {
                _audioClips.Add(audioClipsFromResources[i].name, audioClipsFromResources[i]);
            }

            // init sound
            _sound.InitSound();
        }
Ejemplo n.º 5
0
        public void InitAudioManager()
        {
            if (isPreLoad)
            {
                AudioClip[] audioClips = Resources.LoadAll <AudioClip>(path);
                for (int i = 0; i < audioClips.Length; ++i)
                {
                    _audioClips.Add(audioClips[i].name, audioClips[i]);
                }
            }

            for (int i = 0; i < sfxChannel; ++i)
            {
                WSound sound = prefabSound.Clone <WSound>(transform);
                sound.InitSound();
                sound.OnDeactivated += () => _currentPlaying.RemoveAll(x => x.Same(sound));

                _sources.Add(sound);
            }

            Volume = 1f;
        }
Ejemplo n.º 6
0
        public void StopCurrentPlaying(string audioClipName)
        {
            WSound curPlaying = GetPlayingSound(audioClipName) ?? _currentPlaying.First();

            curPlaying?.StopSound();
        }