Beispiel #1
0
        /// <summary>
        /// 创建依赖关系
        /// </summary>
        private static void CreateAssetBundleDepends()
        {
            AssetBundle         mainAssetBundle = AssetBundle.LoadFromFile(AssetBundleOutPath + "/" + GetPlatformPath(CurrentBuildTarget));
            AssetBundleManifest mainFest        = mainAssetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); //获得主AssetBundleManifest

            RecordPackAbundleMainifestInfor(GetPlatformPath(CurrentBuildTarget));                                         //不同平台的打包主AssetBundle
            RecordPackAbundleMainifestInfor(GetPlatformPath(CurrentBuildTarget) + ".manifest");                           // AssetBundleManifest

            #region 遍历记录所有的AssetBundle
            string[] allAssets = mainFest.GetAllAssetBundles();//获得所有的AssetBundleName
            foreach (var item in allAssets)
            {
                string[] depences = mainFest.GetAllDependencies(item);                                                        //获得当前资源的所有依赖关系
                string   path     = Application.streamingAssetsPath + "/" + GetPlatformPath(CurrentBuildTarget) + "/" + item; //获取打包后的资源AssetBundle 绝对路径

                #region 记录当前AssetBundle 信息
                HotAssetInfor_AssetBundle _infor = new HotAssetInfor_AssetBundle();
                _infor.m_MD5Code = Sercurity.MD5Helper.GetFileMD5(path);
                System.IO.FileInfo fileInfor = new System.IO.FileInfo(path);
                _infor.m_ByteSize = (int)fileInfor.Length;
                _infor.m_Dependece.AddRange(depences);
                if (S_HotAssetRecordInfor.m_AllAssetRecordsDic.ContainsKey(item))
                {
                    Debug.LogError("重复的AssetBundleName=" + item);
                    break;
                }
                S_HotAssetRecordInfor.m_AllAssetRecordsDic.Add(item, _infor);  //记录当前的 AssetBundle 资源
                #endregion

                #region 记录当前文件 .meta信息
                HotAssetInfor_AssetBundle _metaInfor = new HotAssetInfor_AssetBundle();
                _metaInfor.m_MD5Code = Sercurity.MD5Helper.GetFileMD5(path + ".meta");
                FileInfo mataFileInfor = new System.IO.FileInfo(path + ".meta");
                _metaInfor.m_ByteSize = (int)mataFileInfor.Length;
                if (S_HotAssetRecordInfor.m_AllAssetRecordsDic.ContainsKey(item + ".meta"))
                {
                    Debug.LogError("重复的AssetBundleName=" + item + ".meta");
                    break;
                }
                S_HotAssetRecordInfor.m_AllAssetRecordsDic.Add(item + ".meta", _metaInfor);  //记录当前的 AssetBundle 资源
                #endregion
            }
            #endregion

            mainAssetBundle.Unload(true);//卸载所有的 AssetBundle 资源
        }
Beispiel #2
0
        /// <summary>
        /// 记录不同平台打包下生成的主 mainAssetBundle 和 mainFest 信息
        /// </summary>
        /// <param name="fileName"></param>
        private static void RecordPackAbundleMainifestInfor(string fileName)
        {
            string PlatformABundlePath = AssetBundleOutPath + "/" + fileName;

            //当AssetBundle
            HotAssetInfor_AssetBundle _infor = new HotAssetInfor_AssetBundle();

            System.IO.FileInfo fileInfor = new System.IO.FileInfo(PlatformABundlePath);
            _infor.m_ByteSize = (int)fileInfor.Length;
            _infor.m_MD5Code  = Sercurity.MD5Helper.GetFileMD5(PlatformABundlePath);
            S_HotAssetRecordInfor.m_AllAssetRecordsDic.Add(fileName, _infor);


            //.meta
            HotAssetInfor_AssetBundle _metaInfor = new HotAssetInfor_AssetBundle();

            System.IO.FileInfo metaFileInfor = new System.IO.FileInfo(PlatformABundlePath + ".meta");
            _metaInfor.m_ByteSize = (int)metaFileInfor.Length;
            _metaInfor.m_MD5Code  = Sercurity.MD5Helper.GetFileMD5(PlatformABundlePath + ".meta");
            S_HotAssetRecordInfor.m_AllAssetRecordsDic.Add(fileName + ".meta", _metaInfor);
        }