Ejemplo n.º 1
0
 /// <summary>
 /// 下载音频
 /// </summary>
 /// <param name="url">请求的链接</param>
 /// <param name="audioType">音频格式</param>
 /// <param name="action">发生的事件</param>
 /// <returns></returns>
 public static bool DownloadAudioClip(string url, RequestAudioClipEvent action, AudioType audioType = AudioType.AUDIOQUEUE)
 {
     if (IsNull(url, action, action.action))
     {
         return(true);
     }
     Instance.StartCoroutine(Instance.DownloadAudioClipIEnumerator(url, audioType, action));
     return(false);
 }
Ejemplo n.º 2
0
    IEnumerator DownloadAudioClipIEnumerator(string url, AudioType audioType, RequestAudioClipEvent action)
    {
        var request = UnityWebRequestMultimedia.GetAudioClip(url, audioType);

        if (action.downloadProgress != null)
        {
            StartCoroutine(DownloadProgress(request, action.downloadProgress));
        }

        yield return(request.SendWebRequest());

        Dispose(request, () =>
        {
            action.action(DownloadHandlerAudioClip.GetContent(request));
        }, action.error, action.error404, action.error500);
    }