Exemple #1
0
    }                                                         // 進度

    /// <summary>
    ///
    /// </summary>
    /// <param name="fullUrl"></param>
    /// <param name="toPath"></param>
    /// <param name="useCache">如果存在则不下载了!</param>
    public CWWWDownloader(string fullUrl, string toPath, bool useCache = false)
    {
        ToPath    = toPath;
        _SavePath = CResourceModule.GetAppDataPath() + "/" + ToPath;
        UseCache  = useCache;
        CResourceModule.Instance.StartCoroutine(StartDownload(fullUrl));
    }
 public static void ClearPersistentDataPath()
 {
     foreach (string dir in Directory.GetDirectories(CResourceModule.GetAppDataPath()))
     {
         Directory.Delete(dir, true);
     }
 }
Exemple #3
0
    public static string GetExportPath(BuildTarget platfrom)
    {
        string basePath = Path.GetFullPath(Application.dataPath + "/" + CCosmosEngine.GetConfig("AssetBundleRelPath") + "/");

        if (!Directory.Exists(basePath))
        {
            CBuildTools.ShowDialog("路径配置错误: " + basePath);
            throw new System.Exception("路径配置错误");
        }

        string path = null;

        switch (platfrom)
        {
        case BuildTarget.Android:
        case BuildTarget.iPhone:
        case BuildTarget.StandaloneWindows:
            path = basePath + CResourceModule.GetBuildPlatformName() + "/";
            break;

        default:
            CBuildTools.ShowDialog("构建平台配置错误");
            throw new System.Exception("构建平台配置错误");
        }
        return(path);
    }
Exemple #4
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));
    }
Exemple #5
0
    protected override void Init(string url)
    {
        base.Init(url);

        RelativeResourceUrl = url;
        if (CResourceModule.GetResourceFullPath(url, out FullUrl))
        {
            CResourceModule.LogRequest("AssetBundle", FullUrl);
            CResourceModule.Instance.StartCoroutine(LoadAssetBundle(url));
        }
        else
        {
            if (Debug.isDebugBuild)
            {
                CDebug.LogError("[CAssetBundleLoader]Error Path: {0}", url);
            }
            OnFinish(null);
        }
    }
Exemple #6
0
 public static void OpenPersistentDataPath()
 {
     System.Diagnostics.Process.Start(CResourceModule.GetAppDataPath());
 }
    IEnumerator _Init(string path, string assetName)
    {
        IsLoadAssetBundle = CCosmosEngine.GetConfig("IsLoadAssetBundle").ToInt32() != 0;
        AssetInBundleName = assetName;

        UnityEngine.Object getAsset = null;
        if (!IsLoadAssetBundle)
        {
            string extension = System.IO.Path.GetExtension(path);
            path = path.Substring(0, path.Length - extension.Length);  // remove extensions

            getAsset = Resources.Load <UnityEngine.Object>(path);
            if (getAsset == null)
            {
                CDebug.LogError("Asset is NULL(from Resources Folder): {0}", path);
            }
            OnFinish(getAsset);
        }
        else
        {
            var bundleLoader = CAssetBundleLoader.Load(path);

            while (!bundleLoader.IsFinished)
            {
                if (IsReadyDisposed)   // 中途释放
                {
                    bundleLoader.Release();
                    OnFinish(null);
                    yield break;
                }
                Progress = bundleLoader.Progress;
                yield return(null);
            }
            var assetBundle = bundleLoader.Bundle;

            System.DateTime beginTime = System.DateTime.Now;
            if (AssetInBundleName == null)
            {
                // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
                //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset
                //while (!request.isDone)
                //{
                //    yield return null;
                //}
                try
                {
                    CDebug.Assert(getAsset = assetBundle.mainAsset);
                }
                catch
                {
                    CDebug.LogError("[OnAssetBundleLoaded:mainAsset]{0}", path);
                }
            }
            else
            {
                // TODO: 未测试过这几行!~~
                AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object));
                while (!request.isDone)
                {
                    yield return(null);
                }

                getAsset = request.asset;
            }

            CResourceModule.LogLoadTime("AssetFileBridge", path, beginTime);

            if (getAsset == null)
            {
                CDebug.LogError("Asset is NULL: {0}", path);
            }

            bundleLoader.Release();  // 释放Bundle(WebStream)
        }

        if (Application.isEditor)
        {
            if (getAsset != null)
            {
                CResourceLoadObjectDebugger.Create(getAsset.GetType().Name, Url, getAsset as UnityEngine.Object);
            }
        }

        if (getAsset != null)
        {
            // 更名~ 注明来源asset bundle 带有类型
            getAsset.name = string.Format("{0}~{1}", getAsset, Url);
        }
        OnFinish(getAsset);
    }
Exemple #8
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);
            }
        }
    }
Exemple #9
0
 // Prefab Asset打包版本號記錄
 public static string GetBuildVersionTab()
 {
     return(Application.dataPath + "/" + CCosmosEngineDef.ResourcesBuildInfosDir + "/ArtBuildResource_" + CResourceModule.GetBuildPlatformName() + ".txt");
 }
Exemple #10
0
 public static string GetFullSavePath(string relativePath)
 {
     return(CResourceModule.GetAppDataPath() + "/" + relativePath);
 }