コード例 #1
0
ファイル: GameManager.cs プロジェクト: liuyongsz/bmobdemo
    /// <summary>
    /// 资源初始化结束
    /// </summary>
    public void OnResourceInited()
    {
        LuaManager.CreateInstance();
        string url   = LuaUtil.GetRelativePath();
        int    index = url.LastIndexOf("/");

        AssetManager.BaseDownloadingURL = url.Substring(0, index);
        m_openLoginUI = true;

        InitManager();
    }
コード例 #2
0
    /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
    /// </summary>
    IEnumerator <object> OnUpdateResource(System.Action Complete)
    {
        //if (!Define.UpdateMode)
        //{
        //    OnResourceInited();
        //    yield break;
        //}
        if (!GameProxy.Instance.m_IsStart)
        {
            yield return(null);
        }

        TotalUpdateLength = 0;

        string dataPath = LuaUtil.DataPath;              //数据目录
        string url      = AssetManager.BaseDownloadingURL + "/";
        string message  = string.Empty;
        string random   = DateTime.Now.ToString("yyyymmddhhmmss");
        string listUrl  = url + "files.txt?v=" + random;

        if (!Define.UpdateMode)
        {
            Debug.LogWarning("LoadUpdate---->>>" + listUrl);
        }

        WWW www = new WWW(listUrl); yield return(www);

        if (www.error != null)
        {
            OnUpdateFailed(string.Empty);
            yield break;
        }
        if (!Directory.Exists(dataPath))
        {
            Directory.CreateDirectory(dataPath);
        }
        File.WriteAllBytes(dataPath + "files.txt", www.bytes);
        string filesText = www.text;

        string[]      files            = filesText.Split('\n');
        List <string> loaderFiles      = new List <string>();
        List <string> loaderLocalFiles = new List <string>();

        for (int i = 0; i < files.Length; i++)
        {
            if (string.IsNullOrEmpty(files[i]))
            {
                continue;
            }
            string[] keyValue  = files[i].Split('|');
            string   f         = keyValue[0];
            string   localfile = (dataPath + f).Trim();
            string   path      = Path.GetDirectoryName(localfile);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            //string fileUrl = url + f + "?v=" + random;
            string fileUrl   = url + f;
            bool   canUpdate = !File.Exists(localfile);
            if (!canUpdate)
            {
                string remoteMd5 = keyValue[1].Trim();
                string localMd5  = LuaUtil.md5file(localfile);
                canUpdate = !remoteMd5.Equals(localMd5);
                if (canUpdate)
                {
                    File.Delete(localfile);
                }
            }
            if (canUpdate)
            {   //本地缺少文件
                if (!Define.UpdateMode)
                {
                    Debug.Log(fileUrl);
                }
                TotalUpdateLength += int.Parse(keyValue[2]);

                loaderFiles.Add(fileUrl);
                loaderLocalFiles.Add(localfile);
            }
        }

        int cnt = loaderFiles.Count;

        for (int i = 0; i < cnt; i++)
        {
            string fileUrl   = loaderFiles[i];
            string localfile = loaderLocalFiles[i];
            message = "downloading>>" + fileUrl;
            Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

            BeginDownload(fileUrl, localfile);

            while (!(IsDownOK(localfile)))
            {
                yield return(new WaitForEndOfFrame());
            }
        }

        yield return(new WaitForEndOfFrame());

        message    = "更新完成!!";
        loadingstr = message;

        string curl  = LuaUtil.GetRelativePath();
        int    index = curl.LastIndexOf("/");

        AssetManager.BaseDownloadingURL = curl.Substring(0, index);
        m_openLoginUI = true;

        Complete();
        GameProxy.Instance.Init_TextManager();
        Facade.Instance.SendNotification(NotificationID.UPDATE_MESSAGE, message);

        OnResourceInited();
    }