public static void BuildArtAssetBundles() { string path = AssetPackFileManager.PACK_DATA_FILE; if (File.Exists(path)) { string buff = File.ReadAllText(path); PackDataList list = JsonUtility.FromJson <PackDataList>(buff); List <AssetBundleBuild> buildlist = new List <AssetBundleBuild>(); foreach (PackData pack in list.list) { AssetBundleBuild builddata = new AssetBundleBuild() { assetBundleName = pack.abname + PackDefine.AB_EXT, assetNames = pack.assetfiles, }; buildlist.Add(builddata); } string output = PackDefine.StreamingAssets + "/" + PackDefine.FILE_ART_NAME; PigPacker.EmptyDir(output); BuildAssetBundleOptions opt = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle; AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(output, buildlist.ToArray(), opt, EditorUserBuildSettings.activeBuildTarget); PigPacker.DeleteFile(output, "*" + PackDefine.AB_EXT + PackDefine.MANIFEST_EXT, SearchOption.AllDirectories); AssetDatabase.Refresh(); EditorUtility.DisplayDialog("Pack Over", "BuildArtAssetBundles finish", "OK"); } else { Debug.LogErrorFormat("file not exist:{0}", path); } }
//从json中读取PackData public override void LoadConfig() { string path = PACK_DATA_FILE; if (File.Exists(path)) { string buff = File.ReadAllText(path); PackDataList list = JsonUtility.FromJson <PackDataList>(buff); foreach (PackData item in list.list) { m_packdata_map.Add(item.abname, new AssetPackFileImpl(item)); } } }
private void WritePackData() { PackDataList list = new PackDataList(); list.list = packList.ToArray(); string buff = JsonUtility.ToJson(list); string wpath = PackDefine.PACK_DATA_JSON_PATH; if (!Directory.Exists(wpath)) { Directory.CreateDirectory(wpath); } string path = AssetPackFileManager.PACK_DATA_FILE; File.WriteAllText(path, buff); }