IEnumerator OnSoundPlayFinish(float delay, GameObject go, OnSoundEnd endCallback, object endParam) { yield return(new WaitForSeconds(delay)); Stop(go); if (endCallback != null) { endCallback(endParam); } }
public GameObject Play(string name, OnSoundEnd onEndCallback = null, object onEndParam = null) { SoundData dat; GameObject ret = null; if (mSfx.TryGetValue(name, out dat)) { ret = GetAvailable(); if (ret != null) { ret.audio.clip = dat.clip; ret.audio.volume = dat.volume; ret.audio.loop = dat.loop; SoundPlayer sp = ret.GetComponent <SoundPlayer>(); sp.playOnActive = false; sp.defaultVolume = dat.volume; sp.playDelay = dat.delay; sp.Play(); SoundPlaying newPlay = new SoundPlaying() { data = dat, player = sp, startTime = dat.realtime ? Time.realtimeSinceStartup : Time.time, onEndCallback = onEndCallback, onEndParam = onEndParam }; mSfxPlaying.Add(newPlay); // sp.StartCoroutine(OnSoundPlayFinish(dat.clip.length + dat.delay, ret, onEndCallback, onEndParam)); ret.SetActive(true); } /*else { * Debug.LogWarning("Ran out of available sound player for: " + name); * }*/ } else { Debug.LogWarning("sound player not found: " + name); } return(ret); }
public AudioSource Play(string name, OnSoundEnd onEndCallback = null, object onEndParam = null) { SoundData dat; if (mDataLookup.TryGetValue(name, out dat)) { return(Play(dat, onEndCallback, onEndParam)); } else { Debug.LogWarning("Unknown sound: " + name); } return(null); }
IEnumerator DoSoundPlay(SoundPlayer sp, OnSoundEnd endCallback, params object[] endParam) { sp.Play(); while (sp.target.isPlaying) { yield return(null); } Stop(sp); if (endCallback != null) { endCallback(endParam); } }
public SoundPlayer Play(string name, Vector3 position, OnSoundEnd onEndCallback = null, params object[] onEndParam) { SoundData dat; SoundPlayer ret = null; if (mSfx.TryGetValue(name, out dat)) { ret = GetAvailable(); if (ret != null) { ret.transform.position = position; ret.target.clip = dat.clip; ret.target.volume = dat.volume; ret.target.loop = dat.loop; ret.defaultVolume = dat.volume; ret.playDelay = dat.delay; if (ret.target.loop) { ret.Play(); } else { ret.StartCoroutine(DoSoundPlay(ret, onEndCallback, onEndParam)); } } /*else { * Debug.LogWarning("Ran out of available sound player for: " + name); * }*/ } else { Debug.LogWarning("sound player not found: " + name); } return(ret); }
AudioSource Play(SoundData dat, OnSoundEnd onEndCallback, object onEndParam) { AudioSource ret = null; if (mSfxPlayingCount < sfx.Length) { SoundPlaying plyr = mSfxPlaying[mSfxPlayingCount]; mSfxPlayingCount++; plyr.data = dat; plyr.src.clip = dat.clip; plyr.startTime = dat.realtime ? Time.realtimeSinceStartup : Time.time; plyr.onEndCallback = onEndCallback; plyr.onEndParam = onEndParam; plyr.src.volume = dat.volume * UserSettingAudio.instance.soundVolume; plyr.src.loop = dat.loop; if (dat.delay > 0.0f) { audio.PlayDelayed(dat.delay); } else { audio.Play(); } if (!mSoundActive) { StartCoroutine(DoSounds()); } } else { Debug.LogWarning("Ran out of available player for: " + dat.name); } return(ret); }
public AudioSource Play(int index, OnSoundEnd onEndCallback = null, object onEndParam = null) { return(Play(sfx[index], onEndCallback, onEndParam)); }
public SoundPlayer Play(string name, OnSoundEnd onEndCallback = null, params object[] onEndParam) { return(Play(name, Vector3.zero, onEndCallback, onEndParam)); }