Exemple #1
0
    /// <summary>
    /// 生成资源-->AssetBundle映射表
    /// </summary>
    private static void GenResourceDictFile(string sourcePath, AssetBundleManifest manifest)
    {
        // 保存的路径是否存在,不存在则创建一个
        // csv保存的地址
        string   dirpath = string.Format("{0}resource_dict.csv", sourcePath);
        FileInfo fi      = new FileInfo(dirpath);

        if (!fi.Directory.Exists)
        {
            fi.Directory.Create();
        }

        // csv文件写入
        FileStream   fs = new FileStream(dirpath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);

        // 创建csv文件前面几行
        sw.WriteLine(WriteRow(new string[] { "# resource_dict.csv", "" }));
        sw.WriteLine(WriteRow(new string[] { "# 资源目录", "" }));
        sw.WriteLine(WriteRow(new string[] { "# 资源路径", "bundle名" }));
        sw.WriteLine(WriteRow(new string[] { "string", "string" }));
        sw.WriteLine(WriteRow(new string[] { "path", "bundle" }));

        // 遍历该文件下的所有AssetBundles
        foreach (string abName in manifest.GetAllAssetBundles())
        {
            // 载入assetBundle
            string      abPath      = string.Format("{0}{1}", sourcePath, abName);
            AssetBundle assetBundle = AssetBundle.LoadFromFile(abPath);

            // 遍历该assetBundle下所有资源
            foreach (string bundle in assetBundle.GetAllAssetNames())
            {
                // 根据路径载入资源
                UnityEngine.Object ob   = AssetDatabase.LoadMainAssetAtPath(bundle);
                string             path = AssetDatabase.GetAssetPath(ob);

                // 写入数据
                sw.WriteLine(WriteRow(new string[] { path, abName }));
            }

            // 释放资源
            assetBundle.Unload(true);
        }

        //关闭写入
        sw.Close();
        fs.Close();

        // 讲csv文件转成byte文件
        CsvFileMgr.Save(dirpath, false, sourcePath);
    }
Exemple #2
0
    /// <summary>
    /// 生成某个目录下的版本控制文件
    /// </summary>
    private static void GenVersionFile(string sourcePath, string publishPath, Dictionary <string, List <object> > assetBundleInfo, Dictionary <string, string> abPatchDic)
    {
        // 保存的路径是否存在,不存在则创建一个
        // csv保存的地址
        string   dirpath = string.Format("{0}version_tree.csv", sourcePath);
        FileInfo fi      = new FileInfo(dirpath);

        if (!fi.Directory.Exists)
        {
            fi.Directory.Create();
        }

        // csv文件写入
        FileStream   fs = new FileStream(dirpath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);

        //创建csv文件前面几行
        sw.WriteLine(WriteRow(new string[] { "# version_tree.csv", "", "", "", "" }));
        sw.WriteLine(WriteRow(new string[] { "# 版本树", "", "", "", "" }));
        sw.WriteLine(WriteRow(new string[] { "# assetbundle名", "MD5编号", "所在patch", "未压缩资源大小", "压缩资源大小" }));
        sw.WriteLine(WriteRow(new string[] { "string", "string", "string", "int", "int" }));
        sw.WriteLine(WriteRow(new string[] { "bundle", "md5", "patch", "unzip_size", "zip_size" }));

        // 遍历该文件下的所有AssetBundles
        foreach (string abName in assetBundleInfo.Keys)
        {
            List <object> info = assetBundleInfo[abName];

            string patch = abPatchDic.ContainsKey(abName) ? abPatchDic[abName] : "0";

            // 写入数据
            sw.WriteLine(WriteRow(new string[] { abName, info[0].ToString(), patch, info[1].ToString(), info[2].ToString() }));
        }

        //关闭写入
        sw.Close();
        fs.Close();

        // 讲csv文件转成byte文件
        CsvFileMgr.Save(dirpath, false, sourcePath);

        // 讲csv文件转成byte文件
        CsvFileMgr.Save(dirpath, false, publishPath);
    }