Beispiel #1
0
    public static void CreateVersionFile()
    {
        string        resPath = EXPORT_OUT_PATH;
        StringBuilder version = new StringBuilder();

        DjwHelper.ForeachHandle(Application.dataPath + "/StreamingAssets", new List <string> {
            "ab", "txt", "lua"
        }, (string filename) =>
        {
            string baseName = filename.Replace(Application.streamingAssetsPath + Path.DirectorySeparatorChar, "").Replace(@"\", @"/");
            string md5      = MD5File(filename);
            FileInfo info   = new FileInfo(filename);
            string size     = System.Math.Ceiling(info.Length / 1024.0) + "KB";

            //  Debug.Log(System.Math.Ceiling(info.Length / 1024.0) + "KB");
            version.Append(baseName).Append(",").Append(md5).Append(",").Append(size).Append("\n");
        });

        //Manifest md5
        string streamingAssetManifest         = Application.dataPath + "/StreamingAssets/StreamingAssets";
        string streamingAssetManifestbaseName = Path.GetFileName(streamingAssetManifest);
        string streamingAssetManifestmd5      = MD5File(streamingAssetManifest);

        version.Append(streamingAssetManifestbaseName).Append(",").Append(streamingAssetManifestmd5).Append("\n");

        //生成配置文件
        FileStream stream = new FileStream(resPath + "version.ver", FileMode.Create);

        byte[] data = Encoding.UTF8.GetBytes(version.ToString());
        stream.Write(data, 0, data.Length);
        stream.Flush();
        stream.Close();
        Debug.Log(" 版本文件 " + resPath + "version.ver:" + version);
    }
Beispiel #2
0
    static void CreateAssetBundles()
    {
        Debug.Log("开始清空StreamingAssets");
        //DjwHelper.ForeachHandle(Application.dataPath + "/StreamingAssets", new List<string> { "ab", "manifest","ver" }, (string filename) =>
        //{
        //    string assetPath = filename.Replace(Application.dataPath, "Assets");
        //    AssetDatabase.DeleteAsset(assetPath);
        //});
        System.IO.Directory.Delete(Application.streamingAssetsPath, true);
        System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
        Debug.Log("StreamingAssets清空完毕...");

        string[] paths = new string[] { "Atlas", "View", "font", "TexturePic", "Audio", "LuaScripts", "Animation", "OtherRes" };


        List <AssetBundleBuild> buildMap = new List <AssetBundleBuild>();

        foreach (string path in paths)
        {
            string basePath = Application.dataPath + "/Resources/" + path;
            {
                if (buildOnePath.Contains(path))
                {
                    List <string> list = new List <string>();
                    DjwHelper.ForeachHandle(basePath, null, (string filename) =>
                    {
                        string assetPath = filename.Replace(Application.dataPath, "Assets");
                        list.Add(assetPath);
                    });
                    AssetBundleBuild build = new AssetBundleBuild();
                    build.assetBundleName = path + ".ab";
                    build.assetNames      = list.ToArray();
                    buildMap.Add(build);
                }
                else
                {
                    DjwHelper.ForeachHandle(basePath, null, (string filename) =>
                    {
                        string assetPath = filename.Replace(Application.dataPath, "Assets");

                        string baseName        = assetPath.Substring(17);
                        AssetBundleBuild build = new AssetBundleBuild();
                        build.assetBundleName  = baseName.Split('.')[0] + ".ab"; //去掉后缀名
                        build.assetNames       = new string[] { assetPath };

                        buildMap.Add(build);
                    });
                }
            }
        }

        BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, buildMap.ToArray(), BuildAssetBundleOptions.DeterministicAssetBundle |
                                        BuildAssetBundleOptions.DisableWriteTypeTree |
                                        BuildAssetBundleOptions.ChunkBasedCompression, GetCurTarget());

        AssetDatabase.Refresh();
        // ConverTxtToLua();
    }