static IEnumerator StartDownLoad()
    {
        Debug.Log("下载服务器文件到本地");

        UpdateDateCallBack(HotUpdateStatusEnum.Updating, GetHotUpdateProgress(true, true, GetDownLoadFileProgress(0)));

        RecordTable hotupdateData = RecordManager.GetData(c_HotUpdateRecordName);

        for (int i = 0; i < s_downLoadList.Count; i++)
        {
            Hash128 md5Tmp = Hash128.Parse(hotupdateData.GetRecord(s_downLoadList[i].name, "null"));

            if (md5Tmp.Equals(s_downLoadList[i].md5))
            {
                Debug.Log("文件已更新完毕 " + s_downLoadList[i].name);
                //该文件已更新完毕
                UpdateDateCallBack(HotUpdateStatusEnum.Updating, GetHotUpdateProgress(true, true, GetDownLoadFileProgress(i)));
            }
            else
            {
                string downloadPath = s_resourcesFileDownLoadPath + s_downLoadList[i].name;

                WWW www = new WWW(downloadPath);
                yield return(www);

                if (www.error != null && www.error != "")
                {
                    Debug.LogError("下载出错! " + downloadPath + " " + www.error);
                    UpdateDateCallBack(HotUpdateStatusEnum.UpdateFail, GetHotUpdateProgress(true, true, GetDownLoadFileProgress(i)));

                    yield break;
                }
                else
                {
                    Debug.Log("下载成功! " + downloadPath);

                    ResourceIOTool.CreateFile(PathTool.GetAssetsBundlePersistentPath() + "/" + s_downLoadList[i].name, www.bytes);
                    RecordManager.SaveRecord(c_HotUpdateRecordName, s_downLoadList[i].name, s_downLoadList[i].md5.ToString());

                    UpdateDateCallBack(HotUpdateStatusEnum.Updating, GetHotUpdateProgress(true, true, GetDownLoadFileProgress(i)));
                }
            }
        }

        //保存版本信息
        //保存文件信息
        ResourceIOTool.CreateFile(PathTool.GetAssetsBundlePersistentPath() + c_versionFileName, s_versionByteCache);
        ResourceIOTool.CreateFile(PathTool.GetAssetsBundlePersistentPath() + AssetsManifestManager.c_ManifestFileName, s_ManifestByteCache);

        //从stream读取配置
        RecordManager.SaveRecord(c_HotUpdateRecordName, c_useHotUpdateRecordKey, true);

        //重新生成资源配置
        ResourcesConfigManager.LoadResourceConfig();
        AssetsManifestManager.LoadAssetsManifest();
        //延迟2秒卸载Bundle缓存,防止更新界面掉图(更新时间短时,卸载过快界面会掉图)
        //yield return new WaitForSeconds(2);
        ResourceManager.ReleaseAll(false);
        UpdateDateCallBack(HotUpdateStatusEnum.UpdateSuccess, 1);
    }
Esempio n. 2
0
    static Bundle AddRelyBundle(string relyBundleName, AssetBundle asset)
    {
        Debug.LogWarning("Load ab====>" + relyBundleName);
        Bundle tmp = new Bundle();

        tmp.relyCount       = 1;
        tmp.bundle          = asset;
        tmp.mainAsset       = asset.mainAsset;
        tmp.allAsset        = asset.LoadAllAssets();
        tmp.allDependencies = AssetsManifestManager.GetAllDependencies(relyBundleName);

        if (s_bundles.ContainsKey(relyBundleName))
        {
            s_bundles[relyBundleName] = tmp;
        }
        else
        {
            s_bundles.Add(relyBundleName, tmp);
        }

        if (tmp.bundle == null)
        {
            Debug.LogError("AddRelyBundle: " + relyBundleName + " dont exist!");
        }

        return(tmp);
    }
    //加载一个依赖包
    public static Bundle LoadRelyBundle(string relyBundleName)
    {
        Bundle tmp = null;

        string[] AllDependencies = AssetsManifestManager.GetAllDependencies(relyBundleName);

        //加载依赖的依赖包
        for (int i = 0; i < AllDependencies.Length; i++)
        {
            LoadRelyBundle(AllDependencies[i]);
        }

        if (s_bundles.ContainsKey(relyBundleName))
        {
            tmp = s_bundles[relyBundleName];
            tmp.relyCount++;

            if (relyBundleName.ToLower().Contains("_res/shader/card_rely"))
            {
                Debug.LogWarning("LoadRelyBundle " + relyBundleName + " relyCount :" + s_bundles[relyBundleName].relyCount);
            }
        }
        else
        {
            string path = GetBundlePath(relyBundleName);
            tmp = AddRelyBundle(relyBundleName, AssetBundle.LoadFromFile(path));
        }

        return(tmp);
    }
    static bool CheckLocalVersion()
    {
        try
        {
            if (ApplicationManager.Instance.m_useAssetsBundle)
            {
                string path = PathTool.GetAbsolutePath(ResLoadLocation.Streaming, c_versionFileName.ToLower());

#if UNITY_EDITOR
                //判断本地文件是否存在
                if (!File.Exists(path))
                {
                    Debug.LogError("本地 Version 文件不存在,请先创建本地文件!");
                    UpdateDateCallBack(HotUpdateStatusEnum.UpdateFail, 1);
                    return(false);
                }
#endif

                AssetBundle ab = AssetBundle.LoadFromFile(path);

                TextAsset text = ab.LoadAsset <TextAsset>(c_versionFileName);
                string    StreamVersionContent = text.text;

                ab.Unload(true);
                Debug.Log("Streaming版本:" + StreamVersionContent);
                //stream版本
                Dictionary <string, object> StreamVersion = (Dictionary <string, object>)FrameWork.Json.Deserialize(StreamVersionContent);

                //Streaming版本如果比Persistent版本还要新,则更新Persistent版本
                if ((GetInt(StreamVersion[c_largeVersionKey]) > GetInt(s_versionConfig[c_largeVersionKey])) ||
                    (GetInt(StreamVersion[c_smallVersonKey]) > GetInt(s_versionConfig[c_smallVersonKey])
                    ))
                {
                    Debug.Log("Streaming版本比Persistent版本还要新");
                    MemoryManager.FreeMemory();
                    RecordManager.CleanRecord(c_HotUpdateRecordName);
                    Init();
                    AssetsManifestManager.LoadAssetsManifest();
                }
                return(true);
            }
            else
            {
                Debug.Log("没有使用Bundle 无需更新");
                UpdateDateCallBack(HotUpdateStatusEnum.NoUpdate, 0);
                return(false);
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
            UpdateDateCallBack(HotUpdateStatusEnum.UpdateFail, 0);
        }

        return(false);
    }
Esempio n. 5
0
    static Bundle AddBundle(string bundleName, AssetBundle asset)
    {
        //Debug.Log("AddBundle " + bundleName);
        Debug.LogWarning("Load ab====>" + bundleName);
        Bundle bundleTmp = new Bundle();

        string[] AllDependencies = AssetsManifestManager.GetAllDependencies(bundleName);

        if (s_bundles.ContainsKey(bundleName))
        {
            s_bundles[bundleName] = bundleTmp;
        }
        else
        {
            s_bundles.Add(bundleName, bundleTmp);
        }

        bundleTmp.allDependencies = AllDependencies;

        if (asset != null)
        {
            bundleTmp.bundle      = asset;
            bundleTmp.bundle.name = bundleName;
            bundleTmp.mainAsset   = asset.mainAsset;
            bundleTmp.allAsset    = bundleTmp.bundle.LoadAllAssets();

            //延迟卸载资源,因为unity的资源卸载有时会异步
            Timer.DelayCallBack(5, (obj) => {
                if (bundleTmp.bundle != null)
                {
                    bundleTmp.bundle.Unload(false);
                }
            });

            //如果有缓存起来的回调这里一起回调
            if (LoadAsyncDict.ContainsKey(bundleName))
            {
                try
                {
                    LoadAsyncDict[bundleName](LoadState.CompleteState, bundleTmp.GetAeests(null));
                }
                catch (Exception e)
                {
                    Debug.Log("LoadAsync AddBundle " + e.ToString());
                }
            }
        }
        else
        {
            Debug.LogError("AddBundle: " + bundleName + " dont exist!");
        }

        return(bundleTmp);
    }
Esempio n. 6
0
    public static bool CheckLocalVersion()
    {
        try
        {
            string StreamPath = PathTool.GetAbsolutePath(ResLoadLocation.Streaming, c_versionFileName.ToLower());

            //判断本地文件是否存在
            if (!File.Exists(StreamPath))
            {
                Debug.LogError("本地 Version 文件不存在,请先创建本地文件!");
                return(false);
            }
            int s_bigVersion   = 0;
            int s_smallVersion = 0;
            GetVersion(StreamPath, ref s_bigVersion, ref s_smallVersion);
            GameInfoCollecter.AddAppInfoValue("Streaming Bundle Version", s_bigVersion + "." + s_smallVersion);

            string persistentPath = PathTool.GetAssetsBundlePersistentPath() + c_versionFileName;
            //判断沙盒路径是否存在
            if (!File.Exists(persistentPath))
            {
                Debug.Log("沙盒 Version 文件不存在!");
                return(false);
            }

            int p_bigVersion   = 0;
            int p_smallVersion = 0;
            GetVersion(persistentPath, ref p_bigVersion, ref p_smallVersion);
            GameInfoCollecter.AddAppInfoValue("Persistent Bundle Version", p_bigVersion + "." + p_smallVersion);

            Debug.Log("largeVersionKey Streaming " + s_bigVersion + " 本地 " + p_bigVersion);
            Debug.Log("smallVersonKey Streaming  " + s_smallVersion + " 本地 " + p_smallVersion);

            //Streaming版本如果比Persistent版本还要新,则更新Persistent版本
            if (s_bigVersion > p_bigVersion ||
                (s_bigVersion == p_bigVersion && s_smallVersion > p_smallVersion) ||
                (s_bigVersion == p_bigVersion && s_smallVersion == p_smallVersion)
                )
            {
                Debug.Log("Streaming版本比Persistent版本还要新");
                MemoryManager.FreeMemory();
                RecordManager.CleanRecord(c_HotUpdateRecordName);
                AssetsManifestManager.LoadAssetsManifest();
            }
            return(true);
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
            //UpdateDateCallBack(HotUpdateStatusEnum.UpdateFail, 0);
        }

        return(false);
    }
    static Dictionary <string, Bundle> s_bundles = new Dictionary <string, Bundle>();     //所有包

#if !UNITY_WEBGL
    /// <summary>
    /// 同步加载一个bundles
    /// </summary>
    /// <param name="name">bundle名</param>
    public static Bundle LoadBundle(string bundleName)
    {
        string path = GetBundlePath(bundleName);

        string[] AllDependencies = AssetsManifestManager.GetAllDependencies(bundleName);

        //加载依赖包
        for (int i = 0; i < AllDependencies.Length; i++)
        {
            //Debug.Log("" + AllDependencies[i] + " -> " + bundleName);

            LoadRelyBundle(AllDependencies[i]);
        }

        return(AddBundle(bundleName, AssetBundle.LoadFromFile(path)));
    }
Esempio n. 8
0
    private void DrawBundleDependencies()
    {
        dependencieSearchValue = EditorDrawGUIUtil.DrawSearchField(dependencieSearchValue);

        Dictionary <string, string[]> dependencieNamesDic = AssetsManifestManager.GetDependencieNamesDic();

        EditorDrawGUIUtil.DrawScrollView(this, () =>
        {
            foreach (var par in dependencieNamesDic)
            {
                if (!string.IsNullOrEmpty(dependencieSearchValue))
                {
                    bool isSearch = false;

                    foreach (var item in par.Value)
                    {
                        if (item.Contains(dependencieSearchValue))
                        {
                            isSearch = true;
                            break;
                        }
                    }
                    if (!isSearch)
                    {
                        if (par.Key.Contains(dependencieSearchValue))
                        {
                            isSearch = true;
                        }
                    }
                    if (!isSearch)
                    {
                        continue;
                    }
                }
                EditorDrawGUIUtil.DrawFoldout(par.Key, par.Key + "(" + par.Value.Length + ")", () =>
                {
                    EditorDrawGUIUtil.CanEdit = true;
                    foreach (var assName in par.Value)
                    {
                        EditorDrawGUIUtil.DrawBaseValue(assName, assName);
                    }
                    EditorDrawGUIUtil.CanEdit = false;
                });
            }
        }, "box");
    }
    /// <summary>
    /// 卸载依赖包
    /// </summary>
    /// <param name="relyBundleName"></param>
    public static void UnLoadRelyBundle(string relyBundleName)
    {
        if (relyBundleName == "")
        {
            return;
        }

        //if (relyBundleName.Contains("res_models"))
        //{
        //    Debug.Log("UnLoadRelyBundle " + relyBundleName);
        //}

        string[] AllDependencies = AssetsManifestManager.GetAllDependencies(relyBundleName);

        //卸载依赖的依赖包
        for (int i = 0; i < AllDependencies.Length; i++)
        {
            UnLoadRelyBundle(AllDependencies[i]);
        }

        if (s_bundles.ContainsKey(relyBundleName))
        {
            if (relyBundleName.ToLower().Contains("card_black"))
            {
                Debug.LogWarning("UnLoadRelyBundle " + relyBundleName + " relyCount :" + s_bundles[relyBundleName].relyCount);
            }

            s_bundles[relyBundleName].relyCount--;

            if (s_bundles[relyBundleName].relyCount <= 0)
            {
                if (UnloadBundle(s_bundles[relyBundleName]))
                {
                    s_bundles.Remove(relyBundleName);
                }
            }
        }
        else
        {
            Debug.LogError("UnLoadRelyBundle: " + relyBundleName + " dont exist !");
        }
    }
Esempio n. 10
0
    /// <summary>
    /// 更新文件
    /// </summary>
    /// <returns></returns>
    static IEnumerator DownLoadFile()
    {
        UpdateDateCallBack(HotUpdateStatusEnum.DownLoadingManifestFile, GetHotUpdateProgress(true, false, 0));
        //取得服务器版本文件
        WWW www = new WWW(s_ManifestFileDownLoadPath);

        Debug.Log("服务器获取清单文件 :" + s_ManifestFileDownLoadPath);
        //yield return www;

        while (!www.isDone)
        {
            UpdateDateCallBack(HotUpdateStatusEnum.DownLoadingManifestFile, GetHotUpdateProgress(true, false, www.progress));
            yield return(new WaitForEndOfFrame());
        }

        if (www.error != null && www.error != "")
        {
            //下载失败
            Debug.LogError("MD5 DownLoad Error " + www.error);

            UpdateDateCallBack(HotUpdateStatusEnum.Md5FileDownLoadFail, GetHotUpdateProgress(true, false, 0));
            yield break;
        }

        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        s_ManifestCache     = www.assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
        s_ManifestByteCache = www.bytes;
        www.assetBundle.Unload(false);

        UpdateDateCallBack(HotUpdateStatusEnum.DownLoadingManifestFile, GetHotUpdateProgress(true, false, 1));

        s_downLoadList = new List <DownLoadData>();

        CheckBundleList(s_ManifestCache, AssetsManifestManager.GetManifest());

        yield return(StartDownLoad());
    }
    static Bundle AddRelyBundle(string relyBundleName, AssetBundle asset)
    {
        Bundle tmp = new Bundle();

        tmp.bundle          = asset;
        tmp.mainAsset       = asset.mainAsset;
        tmp.allAsset        = asset.LoadAllAssets();
        tmp.allDependencies = AssetsManifestManager.GetAllDependencies(relyBundleName);

        //if(relyBundleName.Contains("res_models"))
        //{
        //    for (int i = 0; i < tmp.allAsset.Length; i++)
        //    {
        //        Debug.Log("allAsset " + tmp.allAsset[i]);
        //    }
        //}

        if (s_bundles.ContainsKey(relyBundleName))
        {
            s_bundles[relyBundleName] = tmp;
            tmp.relyCount++;
        }
        else
        {
            s_bundles.Add(relyBundleName, tmp);
            tmp.relyCount = 1;
        }

        if (relyBundleName.ToLower().Contains("card_black"))
        {
            Debug.LogWarning("AddRelyBundle " + relyBundleName + " relyCount :" + s_bundles[relyBundleName].relyCount);
        }

        if (tmp.bundle == null)
        {
            Debug.LogError("AddRelyBundle: " + relyBundleName + " dont exist!");
        }

        return(tmp);
    }
Esempio n. 12
0
    public static Dictionary <string, Bundle> s_bundles = new Dictionary <string, Bundle>();     //所有包

#if !UNITY_WEBGL
    /// <summary>
    /// 同步加载一个bundles
    /// </summary>
    /// <param name="name">bundle名</param>
    public static Bundle LoadBundle(string bundleName)
    {
        string path = GetBundlePath(bundleName);

        string[] AllDependencies = AssetsManifestManager.GetAllDependencies(bundleName);

        //加载依赖包
        for (int i = 0; i < AllDependencies.Length; i++)
        {
            LoadRelyBundle(AllDependencies[i]);
        }

        if (!AssetsManifestManager.GetIsDependencies(bundleName))
        {
            return(AddBundle(bundleName, AssetBundle.LoadFromFile(path)));
        }
        //如果这个包被别人依赖,则当做依赖包处理
        else
        {
            return(LoadRelyBundle(bundleName));
        }
    }
Esempio n. 13
0
 public override bool IsHaveDependencies(string path)
 {
     return(AssetsManifestManager.IsHaveDependencies(path));
 }
Esempio n. 14
0
 public override string[] GetAllDependenciesName(string path)
 {
     return(AssetsManifestManager.GetAllDependenciesPaths(path));
 }
Esempio n. 15
0
    /// <summary>
    /// 异步加载一个bundle
    /// </summary>
    /// <param name="bundleName">bundle名</param>
    public static void LoadBundleAsync(string bundleName, BundleLoadCallBack callBack)
    {
        string[] AllDependencies = AssetsManifestManager.GetAllDependencies(bundleName);

        string path = GetBundlePath(bundleName);

        LoadState state = new LoadState();

        int LoadCount = 0;

        if (AllDependencies.Length > 0)
        {
            //先加载依赖包
            for (int i = 0; i < AllDependencies.Length; i++)
            {
                if (AllDependencies[i] != "")
                {
                    LoadRelyBundleAsync(AllDependencies[i], (LoadState relyLoadState, Bundle RelyBundle) =>
                    {
                        if (RelyBundle != null && relyLoadState.isDone)
                        {
                            LoadCount++;
                            state.progress += 1 / ((float)AllDependencies.Length + 1);
                        }

                        //所有依赖包加载完毕加载资源包
                        if (LoadCount == AllDependencies.Length)
                        {
                            ResourceIOTool.AssetsBundleLoadAsync(path, (LoadState bundleLoadState, AssetBundle bundle) =>
                            {
                                if (bundleLoadState.isDone)
                                {
                                    callBack(LoadState.CompleteState, AddBundle(bundleName, bundle));
                                }
                                else
                                {
                                    state.progress += bundleLoadState.progress / ((float)AllDependencies.Length + 1);
                                    callBack(state, null);
                                }
                            });
                        }
                        else
                        {
                            callBack(state, null);
                        }
                    });
                }
            }
        }
        else
        {
            ResourceIOTool.AssetsBundleLoadAsync(path, (LoadState bundleLoadState, AssetBundle bundle) =>
            {
                if (bundleLoadState.isDone)
                {
                    callBack(LoadState.CompleteState, AddBundle(bundleName, bundle));
                }
                else
                {
                    state.progress += bundleLoadState.progress / ((float)AllDependencies.Length + 1);
                    callBack(state, null);
                }
            });
        }
    }