public void Fade3D(string layerName, string sourceName, float fromVol, float toVol, float time) { Sound3DLayerData layer = soundLayers3D.FirstOrDefault(l => l.layerName == layerName); if (layer == null) { return; } SoundSourceData sourceData = layer.soundData.sources.FirstOrDefault(c => c.sourceName == sourceName); if (sourceData == null) { return; } GameObject target = sourceData.source.gameObject; SoundFadeCallbackBehabiour cb = target.AddComponent <SoundFadeCallbackBehabiour>(); cb.audioSource = sourceData.source; iTween.ValueTo(target, iTween.Hash( "from", fromVol, "to", toVol, "time", time, "onupdate", "fade_updated", "onupdatetarget", target, "oncomplete", "fade_completed", "oncompletetarget", target)); }
private void fade_completed() { if (audioSource.isPlaying) { audioSource.Stop(); } SoundFadeCallbackBehabiour.Destroy(this); }
public void Fade(string layerName, float fromVol, float toVol, float time) { if (audioSources2D.ContainsKey(layerName)) { GameObject target = audioSources2D[layerName].gameObject; SoundFadeCallbackBehabiour cb = target.AddComponent <SoundFadeCallbackBehabiour>(); cb.audioSource = audioSources2D[layerName]; iTween.ValueTo(target, iTween.Hash( "from", fromVol, "to", toVol, "time", time, "onupdate", "fade_updated", "onupdatetarget", target, "oncomplete", "fade_completed", "oncompletetarget", target)); } }