public void AddLayer(SoundLayerData layer) { if (!soundLayersTable.ContainsKey(layer.layerName)) { soundLayersTable.Add(layer.layerName, layer); // 2D AudioSourceを設定 GameObject go = new GameObject(string.Format("AudioSource 2D [{0}]", layer.layerName)); go.transform.parent = this.gameObject.transform; AudioSource source = go.AddComponent <AudioSource>(); source.playOnAwake = false; audioSources2D.Add(layer.layerName, source); } else { Debug.LogWarning("SoundManager :: layer is already exists."); } }
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(); } } }
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."); } }