Пример #1
0
        public static AudioHandler PlaySound(AudioData ads)
        {
            AudioHandler handler = InstantiateAudioObject();

            handler.AddQueue(ads);
            handler.Play();
            return(handler);
        }
Пример #2
0
        public static AudioHandler PlaySoundAsQueueAtLocation(AudioData[] ads, Vector2 pos)
        {
            AudioHandler handler = InstantiateAudioObject(pos);

            handler.AddQueues(ads);
            handler.Play();
            return(handler);
        }
Пример #3
0
        /// <summary>
        /// 在指定位置播放音效
        /// </summary>
        /// <param name="att">声音属性设置</param>
        /// <param name="pos">坐标</param>
        public static AudioHandler PlaySoundAtLocation(AudioData ads, Vector3 pos)
        {
            AudioHandler handler = InstantiateAudioObject(pos);

            handler.AddQueue(ads);
            //  Debug.Log(ads);
            handler.Play();
            return(handler);
        }
Пример #4
0
        /// <summary>
        /// 在指定位置播放音效
        /// </summary>
        /// <param name="att">声音属性设置</param>
        /// <param name="pos">坐标</param>
        public static AudioHandler PlaySoundAtLocation(AudioAttribute att, Vector3 pos)
        {
            TagHandle(att);
            AudioHandler handler = InstantiateAudioObject(pos);

            AudioEventHandle(att, handler);
            handler.AddQueue(att);
            handler.Play();
            return(handler);
        }
Пример #5
0
        /// <summary>
        /// 附加BGM到摄像头
        /// </summary>
        /// <param name="att"></param>
        public static AudioHandler AttackBGMtoCamera(AudioAttribute att)
        {
            att      = TagHandle(att);
            att.loop = true;
            AudioHandler handler = Camera.main.gameObject.AddComponent <AudioHandler>();

            AudioEventHandle(att, handler);
            handler.AddQueue(att);
            handler.Play();
            return(handler);
        }
Пример #6
0
        public static AudioHandler PlaySoundAsQueueAtLocation(AudioAttribute[] atts, Vector2 pos)
        {
            AudioHandler handler = InstantiateAudioObject(pos);

            foreach (AudioAttribute a in atts)
            {
                TagHandle(a);
                AudioEventHandle(a, handler);
            }
            handler.AddQueues(atts);
            handler.Play();
            return(handler);
        }
Пример #7
0
 /// <summary>
 /// Event统一处理
 /// </summary>
 /// <param name="att"></param>
 /// <param name="handler"></param>
 private static void AudioEventHandle(AudioAttribute att, AudioHandler handler)
 {
     if (att.OnStartPlay != null)
     {
         handler.OnStartPlay += att.OnStartPlay;
     }
     if (att.OnPausePlay != null)
     {
         handler.OnPausePlay += att.OnPausePlay;
     }
     if (att.OnStopPlay != null)
     {
         handler.OnStopPlay += att.OnStopPlay;
     }
 }
Пример #8
0
 public static void DeSpawn(AudioHandler handler)
 {
     if (handler.gameObject.name == "AudioPoolDespawnable")
     {
         list_usingObj.Remove(handler.gameObject);
         list_unusedObj.Add(handler.gameObject);
         handler.gameObject.SetActive(false);
     }
     else
     {
         list_using.Remove(handler);
         list_unused.Add(handler);
         handler.enabled = false;
     }
 }
Пример #9
0
 public static AudioHandler SpawnAudioHandlerl()
 {
     if (list_unused.Count == 0)
     {
         AudioHandler handler = listener.gameObject.AddComponent <AudioHandler>();
         list_using.Add(handler);
         return(handler);
     }
     else
     {
         AudioHandler handler = list_unused[0];
         handler.enabled = true;
         list_unused.RemoveAt(0);
         list_using.Add(handler);
         return(handler);
     }
 }
Пример #10
0
 public static AudioHandler SpawnAudioHandlerl(Vector3 pos)
 {
     if (list_unusedObj.Count == 0)
     {
         GameObject go = new GameObject("AudioPoolDespawnable");
         go.transform.SetParent(AudioController.GetInstance().transform);
         go.transform.position = pos;
         AudioHandler handler = go.AddComponent <AudioHandler>();
         list_usingObj.Add(go);
         return(handler);
     }
     else
     {
         AudioHandler handler = list_unusedObj[0].GetComponent <AudioHandler>();
         handler.gameObject.SetActive(true);
         list_usingObj.Add(handler.gameObject);
         list_unusedObj.RemoveAt(0);
         return(handler);
     }
 }
Пример #11
0
 IEnumerator AutoCull()
 {
     for (;;)
     {
         if (list_unused.Count > poolMax)
         {
             AudioHandler handler = list_unused[list_unused.Count - 1];
             list_unused.Remove(handler);
             Destroy(handler);
         }
         if (list_unusedObj.Count > poolMax)
         {
             GameObject go = list_unusedObj[list_unusedObj.Count - 1];
             list_unusedObj.Remove(go);
             Destroy(go);
         }
         // Debug.Log("auto cull");
         yield return(new WaitForSeconds(cullInterval));
     }
 }