Ejemplo n.º 1
0
    IEnumerator DownloadSong(JLoaderInfo info)
    {
        if (info.url.EndsWith("mp3"))
        {
            info.www = UnityWebRequestMultimedia.GetAudioClip(info.url, AudioType.MPEG);
        }
        else if (info.url.EndsWith("wav"))
        {
            info.www = UnityWebRequestMultimedia.GetAudioClip(info.url, AudioType.WAV);
        }

        info.result = info.www.SendWebRequest();
        yield return(info.result);

        if (!info.www.isNetworkError || string.IsNullOrEmpty(info.www.error))
        {
            Debug.Log(info.www.url + ":下载成功");
            info.callback(DOWNLOAD_TYPE.SUCCESS, info);
        }
        else
        {
            Debug.Log(info.www.url + ":下载失败");
            info.callback(DOWNLOAD_TYPE.FAILED, info);
        }
        info.www.Dispose();
        queue.Remove(info);
    }
Ejemplo n.º 2
0
    public override void Cancel(BaseScene.INPUT_TYPE type, JoystickManager.JOYSTICK_KEY_STATE keyState, JoystickManager.PLAYER_INDEX player)
    {
        Sounder.instance.Play("返回按键");
        if (keyState != JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN)
        {
            return;
        }

        if (alert.gameObject.activeSelf)
        {
            alert.gameObject.SetActive(false);
            return;
        }


        Sounder.instance.Play("返回按键");
        if (downloading)
        {
            confirm.Show(() =>
            {
                if (info != null)
                {
                    JLoader.instance.Remove(info);
                    info = null;
                    CharacterCard card = cards[characterIndex];
                    card.UpdateProgress(-1);
                    downloading = false;
                }
            }, "正在下载,要取消吗?");
        }
        else
        {
            BackToSongList();
        }
    }
Ejemplo n.º 3
0
 public override void Cancel(BaseScene.INPUT_TYPE type, JoystickManager.JOYSTICK_KEY_STATE keyState, JoystickManager.PLAYER_INDEX player)
 {
     if (hasSelect)
     {
         return;
     }
     Sounder.instance.Play("返回按键");
     if (downloading)
     {
         confirm.Show(() => {
             if (info != null)
             {
                 JLoader.instance.Remove(info);
                 info = null;
                 CharacterCard card = cards[index - 1];
                 card.UpdateProgress(-1);
                 downloading = false;
             }
         }, "正在下载,要取消吗?");
     }
     else
     {
         LoadLevel("Prop", false);
     }
 }
Ejemplo n.º 4
0
 internal void Remove(JLoaderInfo info)
 {
     if (info != null && info.www != null)
     {
         info.www.Abort();
     }
     //queue.Remove(info);
 }
Ejemplo n.º 5
0
    private void DownloadVideo()
    {
        if (downloading)
        {
            return;
        }

        CharacterCard card = cards[characterIndex];

        card.undownload.gameObject.SetActive(false);

        if (Global.isAllResLocal)
        {
            downloading = false;
            if (confirm.gameObject.activeSelf)
            {
                confirm.gameObject.SetActive(false);
            }
            SetCharacter(characterIndex, true);
            return;
        }

        if (!Global.instance.CheckVideoDownload(card.data))
        {
            downloading = true;
            info        = Global.instance.DownloadVideo(card.data, (per) =>
            {
                if (per == -1)
                {
                    downloading = false;
                    alert.Show("网络异常或磁盘容量不足");
                    Sounder.instance.Play("BAD音效");
                    if (confirm.gameObject.activeSelf)
                    {
                        confirm.gameObject.SetActive(false);
                    }
                }
                else if (per == 1)
                {
                    downloading = false;
                    alert.Show("加载成功!");
                    if (confirm.gameObject.activeSelf)
                    {
                        confirm.gameObject.SetActive(false);
                    }
                }
                card.UpdateProgress(per);
            });
        }
        else
        {
            SetCharacter(characterIndex, true);
        }
    }
Ejemplo n.º 6
0
    public JLoaderInfo Load(string url, object userdata, Action <DOWNLOAD_TYPE, JLoaderInfo> callback)
    {
        JLoaderInfo info = new JLoaderInfo();

        info.url      = url;
        info.callback = callback;
        //info.www = new WWW(url);
        info.userData = userdata;
        queue.Add(info);
        if (url.EndsWith("wav") || url.EndsWith("mp3"))
        {
            StartCoroutine(DownloadSong(info));
        }
        else
        {
            StartCoroutine(Download(info));
        }
        return(info);
    }
Ejemplo n.º 7
0
    IEnumerator Download(JLoaderInfo info)
    {
        using (info.www = UnityWebRequest.Get(info.url))
        {
            info.result = info.www.Send();
            yield return(info.result);

            if (!info.www.isNetworkError || string.IsNullOrEmpty(info.www.error))
            {
                Debug.Log(info.www.url + ":下载成功");
                info.callback(DOWNLOAD_TYPE.SUCCESS, info);
            }
            else
            {
                Debug.Log(info.www.url + ":下载失败-" + info.www.error);
                info.callback(DOWNLOAD_TYPE.FAILED, info);
            }
            queue.Remove(info);
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        for (int i = 0, c = queue.Count; i < c; i++)
        {
            JLoaderInfo info = queue[i];
            //if (info.www.isDone)
            //{
            //    if (info.www.error != null)
            //    {
            //        //Debug.Log(info.www.url + ":加载失败");
            //        info.callback(DOWNLOAD_TYPE.FAILED, info);
            //        queue.Remove(info);
            //    }
            //    else
            //    {
            //        info.callback(DOWNLOAD_TYPE.SUCCESS, info);
            //        queue.Remove(info);
            //    }
            //    //info.www.Dispose();
            //    //deleteItem.Add(info);
            //}
            //else
            //{
            info.callback(DOWNLOAD_TYPE.PROGRESS, info);
            //}
        }

        //if (deleteItem.Count > 0)
        //{
        //    for (int i = 0, c = deleteItem.Count; i < c; i++)
        //    {
        //        queue.Remove(deleteItem[i]);
        //    }
        //    deleteItem.Clear();
        //}
    }
Ejemplo n.º 9
0
    /// <summary>
    /// 下载歌曲
    /// </summary>
    /// <param name="callback"></param>
    public JLoaderInfo[] DownloadSong(SongData data, bool isGetInfo, Action <float, SongInfo> callback)
    {
        //如果文件都存在本地
        SongInfo info = new SongInfo();

        info.data = data;

        bool   readLocal          = false;
        string persistentDataPath = AppContentPath();

        if (!data.local)
        {
            if ((File.Exists(persistentDataPath + data.enName + ".mp3") || File.Exists(persistentDataPath + data.enName + ".wav")) &&
                File.Exists(persistentDataPath + data.enName + "_easy.txt") &&
                File.Exists(persistentDataPath + data.enName + "_mid.txt") &&
                File.Exists(persistentDataPath + data.enName + "_hard.txt") &&
                File.Exists(persistentDataPath + data.cover + ".png"))
            {
                readLocal = true;
            }
        }

        //string[] downloadFileName = {  data.enName + ".mp3",
        //                         data.enName + "_easy.txt",
        //                         data.enName + "_mid.txt",
        //                        data.enName + "_hard.txt",
        //                        data.cover + ".png"
        //                            };
        string[] downloadFileName = { data.enName + ".wav",
                                      data.enName + "_easy.txt",
                                      data.enName + "_mid.txt",
                                      data.enName + "_hard.txt",
                                      data.cover + ".png" };

        float[] percents = new float[downloadFileName.Length];
        bool    failed   = false;

        JLoaderInfo[] infos = new JLoaderInfo[downloadFileName.Length];
        for (int i = 0; i < downloadFileName.Length; i++)
        {
            string n = downloadFileName[i];
            string p;
            if (readLocal)
            {
                p = AppContentPathOfWWW() + n;
            }
            else
            {
                if (!data.local)
                {
                    p = RES_HOST + "music/" + n;
                }
                else
                {
                    p = AppStreamPath("music/" + n);
                }
            }
            float[] pp = percents;
            Debug.Log("加载" + p);
            infos[i] = JLoader.instance.Load(p, i, (type, jinfo) =>
            {
                if (failed)
                {
                    return;
                }
                switch (type)
                {
                case JLoader.DOWNLOAD_TYPE.SUCCESS:
                    percents[(int)jinfo.userData] = 1;
                    if (isGetInfo)
                    {
                        if (p.IndexOf(".wav") != -1)
                        {
                            //info.songClip = jinfo.www.GetAudioClip(false);
                            info.songClip = DownloadHandlerAudioClip.GetContent(jinfo.www);
                        }
                        else if (p.IndexOf("_easy") != -1)
                        {
                            info.ParseEasy(jinfo.www.downloadHandler.text);
                        }
                        else if (p.IndexOf("_mid") != -1)
                        {
                            info.ParseMid(jinfo.www.downloadHandler.text);
                        }
                        else if (p.IndexOf("_hard") != -1)
                        {
                            info.ParseHard(jinfo.www.downloadHandler.text);
                        }
                        else if (p.IndexOf(".png") != -1)
                        {
                            info.bytes = jinfo.www.downloadHandler.data;
                        }
                    }

                    if (!readLocal && data.local == false)
                    {
                        string outfile = AppContentPath() + n;
                        string dir     = Path.GetDirectoryName(outfile);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        File.WriteAllBytes(outfile, jinfo.www.downloadHandler.data);
                    }
                    break;

                case JLoader.DOWNLOAD_TYPE.FAILED:
                    failed = true;
                    Debug.Log(p + " 加载失败~" + jinfo.www.error);
                    callback(-1, null);
                    break;
                }
                pp[(int)jinfo.userData] = jinfo.www.downloadProgress;
                bool allDone            = true;
                float allPer            = 0;
                for (int j = 0; j < percents.Length; j++)
                {
                    if (allDone && percents[j] != 1)
                    {
                        allDone = false;
                    }
                    if (percents[j] != -1)
                    {
                        allPer += percents[j];
                    }
                }
                if (allPer == -1 * downloadFileName.Length)
                {
                    callback(-1, null);
                }
                else
                {
                    callback(allPer / (float)percents.Length, info);
                }
            });
        }
        return(infos);
    }