Example #1
0
    //--------------------------------------------------------------------------------------------
    public IEnumerator NtfDownOrLoad(bool bLocal)
    {
        GameResMng.SetLoading();
        string sf = ResPath.GetLocal(mFile);

        if (bLocal) // 从本地读取的话要确保资源存在
        {
            try
            {
                if (!File.Exists(sf))   // 本地不存在依然从网上下载
                {
                    bLocal = false;
                }
            }
            catch (Exception exp)
            {
                Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message);
            }
        }
        string sUrl = "";

        if (bLocal)
        {
            sUrl = ResPath.WLocalUrl(mFile);
        }
        else // 从网上下载
        {
            sUrl = ResPath.GetUrl(mFile);
        }
        Debug.Log("Download, URL = " + sUrl);
        GameResMng.DebugMsg = "Download, URL = " + sUrl;

        //WWW.LoadFromCacheOrDownload(sUrl,1);//
        mWLoad = new WWW(sUrl);
        yield return(mWLoad);

        if ((!bLocal) && mWLoad.isDone)
        {
            ResPath.SaveToLocal(sf, mWLoad.bytes);
            Clean();
        }
        if (null != mWLoad.error)
        {
            Debug.LogError(mWLoad.error);
        }
        ApplyPackge();
    }
Example #2
0
    public IEnumerator TryDownload(bool isClean, bool forceDownload)
    {
        if (mWLoad != null)
        {
            yield break;
        }
        GameResMng.SetLoading();
        string sf             = ResPath.GetLocal(mFile);
        bool   isNeedDownload = forceDownload;

        try
        {
            if (!File.Exists(sf))   // 本地不存在依然从网上下载
            {
                isNeedDownload = true;
                m_state        = State.Downloading;
            }
            else if (isClean)
            {
                m_state = State.LocalReady;
            }
        }
        catch (Exception exp)
        {
            Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message);
        }
        string sUrl = "";

        if (isNeedDownload || !isClean)
        {
            if (isNeedDownload)
            {
                sUrl = ResPath.GetUrl(mFile);
            }
            else
            {
                sUrl = ResPath.WLocalUrl(mFile);
            }
            Debug.Log("BeginDownload, URL = " + sUrl);
            GameResMng.DebugMsg = "Download, URL = " + sUrl;
            m_state             = State.Downloading;
            mWLoad = new WWW(sUrl);
            yield return(mWLoad);

            if (null != mWLoad.error)
            {
                m_state = State.Failed;
                Debug.LogError("Error, URL = " + sUrl + "   " + mWLoad.error);
                GameResMng.GetResMng().OnPackageDownloadFailed(mFile);
            }
            else if (IsDone())
            {
                m_state = State.LocalReady;
                if (isNeedDownload)
                {
                    ResPath.SaveToLocal(sf, mWLoad.bytes);
                }
                GameResMng.GetResMng().OnPackageDownload(mFile, mWLoad.bytes.Length);
            }
            if (isClean)
            {
                Clean();
                Resources.UnloadUnusedAssets();
                GC.Collect();
            }
            string msg = "EndDownload, URL = " + sUrl;
            if (isClean)
            {
                msg += "[Clean]";
            }
            Debug.Log(msg);
            //
        }
        ApplyPackge();
    }