public void PlayEffect(string song, float volume = 1f, string key = "", float delta = 0.03f) { SoundEffectSetup setup = new SoundEffectSetup(); setup.volume = volume; setup.key = key; setup.delta = delta; this._PlayEffect(song, setup); }
public void PlayEffect(string song, float volume, float pitch, bool loop, string key = "", float delta = 0.03f) { SoundEffectSetup setup = new SoundEffectSetup(); setup.volume = volume; setup.pitch = pitch; setup.loop = loop; setup.key = key; setup.delta = delta; this._PlayEffect(song, setup); }
public void PlayEffect(string song, float volume, float pitch, Transform spacialParent, float spacialMaxDistance, bool loop = false, string key = "", float delta = 0.03f) { SoundEffectSetup setup = new SoundEffectSetup(); setup.volume = volume; setup.pitch = pitch; setup.spacialParent = spacialParent; setup.spacialMaxDistance = spacialMaxDistance; setup.loop = loop; setup.key = key; setup.delta = delta; this._PlayEffect(song, setup); }
private void _PlayEffect(string song, SoundEffectSetup setup) { if (this.ycManager.ycConfig.SoundEffect && this.ycManager.dataManager.GetSoundEffect() == true) { if (this._rc.effects.ContainsKey(song)) { string key = song + setup.key; if (this._effects.ContainsKey(key) == false || Time.time >= this._effects[key].time) { SoundElement se = null; AudioClip clip = this._rc.effects[song]; if (this._effects.ContainsKey(key) == false) { se = new SoundElement(); se.audioSource = this.AddGameObject <AudioSource>("AudioSourceEffects-" + song); this._effects.Add(key, se); } else { se = this._effects[key]; } se.time = Time.time + setup.delta; se.audioSource.volume = setup.volume; se.audioSource.pitch = setup.pitch; if (setup.spacialParent != null) { se.audioSource.transform.SetParent(setup.spacialParent); se.audioSource.transform.localPosition = Vector3.zero; se.audioSource.maxDistance = setup.spacialMaxDistance; se.audioSource.spatialBlend = 1f; } if (setup.loop == true) { se.audioSource.clip = clip; se.audioSource.loop = setup.loop; se.audioSource.Play(); } else { se.audioSource.PlayOneShot(clip); } } } else { Debug.LogError("[SOUNDMANAGER] EFFECT NOT FOUND " + song); } } }