public void Play(string layerName, string clipName, bool overlap, bool loop, bool asOneShot)
        {
            if (!audioSources2D.ContainsKey(layerName))
            {
                return;
            }

            SoundLayerData layer = soundLayers.FirstOrDefault(l => l.layerName == layerName);

            if (layer == null)
            {
                return;
            }

            if (layer.soundData.use)
            {
                SoundClipData clipData = layer.soundData.clips.FirstOrDefault(c => c.clipName == clipName);
                if (clipData == null)
                {
                    return;
                }

                if (!overlap)
                {
                    if (audioSources2D[layerName].isPlaying)
                    {
                        audioSources2D[layerName].Stop();
                    }
                }

                audioSources2D[layerName].volume = layer.soundData.volume;
                audioSources2D[layerName].clip   = clipData.clip;

                if (asOneShot)
                {
                    audioSources2D[layerName].PlayOneShot(clipData.clip);
                }
                else
                {
                    audioSources2D[layerName].loop = loop;
                    audioSources2D[layerName].Play();
                }
            }
        }
예제 #2
0
        // SEの再生
        public void PlaySE(string clipName, bool overlap = false)
        {
            if (sound_SE.use)
            {
                if (!overlap)
                {
                    if (audioSource_SE.isPlaying)
                    {
                        audioSource_SE.Stop();
                    }
                }

                audioSource_SE.volume = sound_SE.volume;

                SoundClipData clipData = sound_SE.clips.First(c => c.name == clipName);
                if (clipData != null)
                {
                    audioSource_SE.PlayOneShot(clipData.clip);
                }
            }
        }
        public void AddClip(string layerName, string clipName, AudioClip clip)
        {
            if (!soundLayersTable.ContainsKey(layerName))
            {
                SoundLayerData layer = new SoundLayerData();
                layer.layerName = layerName;
                AddLayer(layer);
            }

            SoundClipData exist = soundLayersTable[layerName].soundData.clips.Find((c) => c.clipName == clipName);

            if (exist == null)
            {
                SoundClipData clipData = new SoundClipData();
                clipData.clipName = clipName;
                clipData.clip     = clip;
                soundLayersTable[layerName].soundData.clips.Add(clipData);
            }
            else
            {
                Debug.LogWarning("SoundManager :: clip is already exists.");
            }
        }
예제 #4
0
        // BGMの再生
        public void PlayBGM(string clipName, bool loop = true, bool overlap = false)
        {
            if (sound_BGM.use)
            {
                if (!overlap)
                {
                    if (audioSource_BGM.isPlaying)
                    {
                        audioSource_BGM.Stop();
                    }
                }

                audioSource_BGM.volume = sound_BGM.volume;

                SoundClipData clipData = sound_BGM.clips.First(c => c.name == clipName);
                if (clipData != null)
                {
                    audioSource_BGM.clip = clipData.clip;
                    audioSource_BGM.loop = loop;
                    audioSource_BGM.Play();
                }
            }
        }