static void Initialize() { listener = GameObject.FindObjectOfType <AudioListener>(); if (!instance) { GameObject pool = new GameObject("AudioPool") { hideFlags = HideFlags.HideInHierarchy }; instance = pool.AddComponent <AudioPool>(); } }
/// <summary> /// 协程延时执行声音播放完成事件 /// </summary> /// <param name="time">延迟时间</param> /// <returns></returns> IEnumerator StopEvent(float time) { yield return(new WaitForSeconds(time * Time.timeScale)); if (OnStopPlay != null) { OnStopPlay(this, new AudioEventArgs(source.clip.name, queuesIndex)); } if (queuesIndex + 1 == AudioQueues.Count) { // Destroy(this.gameObject); if (!notDespawn) { AudioPool.DeSpawn(this); } } else { Debug.LogError("on stop going next"); Play(); } }
private static AudioHandler InstantiateAudioObject() { return(AudioPool.SpawnAudioHandlerl()); }
/// <summary> /// 在指定位置生成音效物体并增加音效脚本 /// </summary> /// <param name="pos">坐标</param> /// <returns></returns> private static AudioHandler InstantiateAudioObject(Vector3 pos) { return(AudioPool.SpawnAudioHandlerl(pos)); }