예제 #1
0
 void OnApplicationQuit()
 {
     isQuit = true;
     JZLog.Log("Quit GameWorld");
     NetworkManager.instance.Close();
     ResHelper.Instance().StopDownloadHttp();
 }
예제 #2
0
    // Where we actuall call WWW to download the assetBundle.
    protected bool LoadAssetBundleInternal(string assetBundleName, int level = 0)
    {
        // Already loaded.
        LoadedAssetBundle bundle = null;

        m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
        if (bundle != null)
        {
            bundle.m_ReferencedCount++;
            return(true);
        }

        // @TODO: Do we need to consider the referenced count of WWWs?
        // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
        // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
        if (m_DownloadingBundles.Contains(assetBundleName))
        {
            return(true);
        }

        VersionBundle vb = null;

        VersionHelper.instance.GetBundleHttp(assetBundleName, out vb);
        if (vb != null)
        {
            string id = vb.versionValue + "_" + vb.id;
            if (ResHelper.Instance().downloadedFiles.ContainsKey(id))
            {
                string url = PathUtils.MakeFilePath(id, PathUtils.PathType.MobileDiskWrite);
                AssetBundleCreateRequest abcr = AssetBundle.LoadFromFileAsync(url);
                m_InProgressOperations.Add(new AssetBundleDownloadFromFile(assetBundleName, abcr, url));
            }
            else
            {
                string url = GameConfig.HOST_RES() + vb.id + "?v=" + vb.versionValue;
                m_InProgressOperations.Add(new AssetBundleDownloadFromWebOperation(assetBundleName, url, vb.versionValue, vb.crc, level));
            }
        }
        else
        {
            PathUtils.PathType       eType = PathUtils.PathType.None;
            string                   url   = PathUtils.GetReadablePath(assetBundleName, ref eType, false);
            AssetBundleCreateRequest abcr  = AssetBundle.LoadFromFileAsync(url);
            m_InProgressOperations.Add(new AssetBundleDownloadFromFile(assetBundleName, abcr, url));
        }
        m_DownloadingBundles.Add(assetBundleName);

        return(false);
    }
예제 #3
0
    /// <summary>
    /// 加载版本文件
    /// </summary>
    /// <param name="onComplete"></param>
    /// <param name="onError"></param>
    public void LoadVersion(Action onComplete, Action onError)
    {
        string url = GameConfig.HOST_RES() + GameConfig.LOCAL_HTTP_CONFIG_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond();

        BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(url), (req, resp) => {
            if (resp != null)
            {
                Loom.RunAsync(() =>
                {
                    m_httpConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(resp.DataAsText);
                    M_CacheHttpBundles();

                    string infoFilePath = PathUtils.MakeFilePath(GameConfig.LOCAL_DOWNLOAD_INFO_FILE, PathUtils.PathType.MobileDiskWrite);
                    if (File.Exists(infoFilePath))
                    {
                        using (FileStream infoStream = File.OpenRead(infoFilePath))
                        {
                            if (infoStream != null)
                            {
                                byte[] index = new byte[infoStream.Length];
                                infoStream.Read(index, 0, index.Length);
                                string content = System.Text.Encoding.Default.GetString(index);
                                DownloadFileInfo downloadFileInfo = JsonFx.Json.JsonReader.Deserialize <DownloadFileInfo>(content);
                                ResHelper.Instance().lastZipIndex = downloadFileInfo.totalSize;
                                for (int i = 0; i < downloadFileInfo.ids.Length; i++)
                                {
                                    ResHelper.Instance().downloadedFiles.Add(downloadFileInfo.ids[i], 1);
                                }
                            }
                        }
                    }

                    if (GameConfig.useLocalRes)
                    {
                        m_version         = new VersionConfig();
                        m_version.version = "0.0.0";
                        Loom.QueueOnMainThread(() => {
                            if (onComplete != null)
                            {
                                onComplete();
                            }
                        });
                    }
                    else
                    {
                        url = GameConfig.HOST_RES_ZIP() + "zip/" + GameConfig.LOCAL_VERSION_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond();
                        BestHTTP.HTTPRequest zipRequest = new BestHTTP.HTTPRequest(new Uri(url), (zipReq, zipResp) => {
                            if (zipResp != null)
                            {
                                m_version = JsonFx.Json.JsonReader.Deserialize <VersionConfig>(zipResp.DataAsText);
                                if (null != onComplete)
                                {
                                    onComplete();
                                }
                            }
                            else
                            {
                                if (null != onError)
                                {
                                    onError();
                                }
                            }
                        });
                        zipRequest.Send();
                    }
                });
            }
            else
            {
                if (null != onError)
                {
                    onError();
                }
            }
        });
        request.DisableCache = true;
        request.Send();
    }