Exemplo n.º 1
0
    public IEnumerator LoadObjectAsync(string sfile, MonoBehaviour delegateYield, ResPackge.AsyncLoadData data)
    {
        string sUrl = ResPath.WLocalUrl(mFile);

        m_canCleanCount++;
        if (m_state == State.LocalReady)
        {
            if (!IsDone() && m_state == State.LocalReady)
            {
                Debug.Log("LoadObjectAsync open package, URL = " + sUrl);
                if (mWLoad == null)
                {
                    mWLoad = new WWW(sUrl);
                }
                m_lockCount++;
                yield return(mWLoad);

                //yield return new WaitForSeconds(2);
                if (mWLoad == null || null != mWLoad.error)
                {
                    m_state = State.Failed;
                    if (mWLoad != null)
                    {
                        Debug.LogError(mWLoad.error);
                    }
                }

                ApplyPackge();
                m_lockCount--;
            }
            if (IsDone())
            {
                AssetBundle bundle = mWLoad.assetBundle;
                data.m_res   = bundle.LoadAsset(sfile, typeof(UnityEngine.Object));
                data.m_owner = this;
                //Clean();
                if (!m_isKeepAlive && m_lockCount == 0)
                {
                    GameResMng.GetResMng().AddDelayCleanPackage(this);
                    //Clean();
                }
            }
            else
            {
                Debug.LogError("Open package Failed, URL = " + sUrl);
            }
        }
        m_canCleanCount--;
        data.IsFinish = true;
    }
Exemplo n.º 2
0
    string GetLocalUrl()
    {
        string sf = ResPath.GetLocal(mFile);

        try
        {
            if (!File.Exists(sf))   // 本地不存在依然从网上下载
            {
            }
        }
        catch (Exception exp)
        {
            Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message);
        }
        return(ResPath.WLocalUrl(mFile));
    }
Exemplo n.º 3
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();
    }
Exemplo n.º 4
0
    public IEnumerator LoadPackageAsync(ResPackge.AsyncLoadData data)
    {
        string sUrl = ResPath.WLocalUrl(mFile);

        m_canCleanCount++;
        if (m_state == State.LocalReady)
        {
            if (!IsDone() && m_state == State.LocalReady)
            {
//				float t = Time.realtimeSinceStartup;
                Debug.Log("Open package, URL = " + sUrl);
                if (mWLoad == null)
                {
                    mWLoad = new WWW(sUrl);
                }
                m_lockCount++;
                yield return(mWLoad);

                //yield return new WaitForSeconds(1);
                if (null != mWLoad.error)
                {
                    m_state = State.Failed;
                    Debug.LogError(mWLoad.error);
                }

                ApplyPackge();
                m_lockCount--;
            }
            if (IsDone())
            {
            }
            else
            {
                Debug.LogError("Open package Failed, URL = " + sUrl);
            }
        }
        m_canCleanCount--;
        data.IsFinish = true;
    }
Exemplo n.º 5
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();
    }