Beispiel #1
0
    // 仅在PC版可用
    string LoadSettingOutPackage(string path)
    {
        string fullPath = CResourceModule.ApplicationPath + path;

        fullPath = fullPath.Replace(CResourceModule.GetFileProtocol(), "");

        System.Text.Encoding encoding = System.Text.Encoding.UTF8;

        return(System.IO.File.ReadAllText(fullPath, encoding));
    }
Beispiel #2
0
    /// <summary>
    /// 协和加载Assetbundle,加载完后执行callback
    /// </summary>
    /// <param name="url">资源的url</param>
    /// <param name="callback"></param>
    /// <param name="callbackArgs"></param>
    /// <returns></returns>
    IEnumerator CoLoad(string url)
    {
        CResourceModule.LogRequest("WWW", url);
        System.DateTime beginTime = System.DateTime.Now;

        // 潜规则:不用LoadFromCache~它只能用在.assetBundle
        Www = new WWW(url);

        WWWLoadingCount++;

        //设置AssetBundle解压缩线程的优先级
        Www.threadPriority = Application.backgroundLoadingPriority;  // 取用全局的加载优先速度
        while (!Www.isDone)
        {
            Progress = Www.progress;
            yield return(null);
        }

        yield return(Www);

        WWWLoadingCount--;
        Progress = 1;
        if (IsReadyDisposed)
        {
            CDebug.LogError("[CWWWLoader]Too early release: {0}", url);
            OnFinish(null);
            yield break;
        }
        if (!string.IsNullOrEmpty(Www.error))
        {
            string fileProtocol = CResourceModule.GetFileProtocol();
            if (url.StartsWith(fileProtocol))
            {
                string fileRealPath = url.Replace(fileProtocol, "");
                CDebug.LogError("File {0} Exist State: {1}", fileRealPath, System.IO.File.Exists(fileRealPath));
            }
            CDebug.LogError("[CWWWLoader:Error]" + Www.error + " " + url);

            OnFinish(null);
            yield break;
        }
        else
        {
            CResourceModule.LogLoadTime("WWW", url, beginTime);
            if (WWWFinishCallback != null)
            {
                WWWFinishCallback(url);
            }

            Desc = string.Format("{0}K", Www.bytes.Length / 1024f);
            OnFinish(Www);
        }

        // 预防WWW加载器永不反初始化, 造成内存泄露~
        if (Application.isEditor)
        {
            while (GetCount <CWWWLoader>() > 0)
            {
                yield return(null);
            }

            yield return(new WaitForSeconds(5f));

            while (Debug.isDebugBuild && !IsReadyDisposed)
            {
                CDebug.LogError("[CWWWLoader]Not Disposed Yet! : {0}", this.Url);
                yield return(null);
            }
        }
    }