예제 #1
0
        //读取streamingAssets path里面的abinfo
        private static void ReadAssetToABInfos(string[] allBundles, FileManifest streamingManifest)
        {
            string title = "create crc list content ";

            var   allABInfos = new List <ABInfo>();
            float i          = 0;
            float allLen     = allBundles.Length;

            //忽略列表
            Dictionary <string, bool> ignore = new Dictionary <string, bool>();

            ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true);
            ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true);
            ignore.Add(CUtils.GetRightFileName(CUtils.platform), true);

            string extension;

            foreach (var str in allBundles)
            {
                string url     = Path.Combine(Application.dataPath, str);
                uint   outCrc  = 0;
                uint   fileLen = 0;
                string abName  = str.Replace("\\", "/");
                string key     = EditorUtils.GetAssetBundleName(abName);
                //后缀替换
                extension = System.IO.Path.GetExtension(key);
                if (extension.Equals(Common.DOT_BYTES))//lua
                {
                    key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX);
                }

                if (!ignore.ContainsKey(key))
                {
                    outCrc = CrcCheck.GetLocalFileCrc(url, out fileLen);
                    var extendsABinfo = streamingManifest.GetABInfo(key);
                    if (extendsABinfo == null)
                    {
                        extendsABinfo = new ABInfo(key, outCrc, fileLen, 0);
                        streamingManifest.Add(extendsABinfo);
                    }
                    extendsABinfo.priority  = 0;
                    extendsABinfo.crc32     = outCrc;
                    extendsABinfo.size      = fileLen;
                    extendsABinfo.assetPath = str;
                    allABInfos.Add(extendsABinfo);
                }
                EditorUtility.DisplayProgressBar(title, title + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }

            EditorUtility.ClearProgressBar();
        }
예제 #2
0
        public static void GenerateAssetBundlesMd5Mapping(string[] allAssets)
        {
            string info = "Generate AssetBundles Md5Mapping ";

            EditorUtility.DisplayProgressBar("GenerateAssetBundlesMd5Mapping", info, 0);
            string        speciallyPath = "Assets/Config/Lan/";
            string        luaPath       = "Assets/Lua/";
            AssetImporter import        = null;
            float         i             = 0;
            float         allLen        = allAssets.Length;
            string        name          = "";
            string        nameMd5       = "";

            //name mapping
            StringBuilder nameSb = new StringBuilder();

            //asset map
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("return {");

            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                string line = string.Empty;

                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    string abName = import.assetBundleName;
                    name = CUtils.GetAssetName(path).ToLower();

                    if (!string.IsNullOrEmpty(import.assetBundleVariant))
                    {
                        abName = import.assetBundleName + "." + import.assetBundleVariant; // line = "{\"" + import.assetBundleName + "\" = { size = \"" + name + "\", path = \"" + path + "\"}},";
                    }
                    line = "[\"" + abName + "\"] = { size = " + GetAssetbundleSize(abName) + ", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", CUtils.GetRightFileName(name), name);
                    if (name.Contains(" "))
                    {
                        Debug.LogWarning(name + " contains space");
                    }
                }
                else if (import != null && path.Contains(speciallyPath))
                {
                    name = CUtils.GetAssetName(path).ToLower();
                    string md5name = CUtils.GetRightFileName(name) + Common.CHECK_ASSETBUNDLE_SUFFIX;
                    line = "[\"" + md5name + "\"] = { size = " + GetAssetbundleSize(md5name) + ", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", md5name, name);
                }
                else if (import != null && path.Contains(luaPath))
                {
                    string luaname    = path.Replace(luaPath, "").Replace("\\", ".").Replace("/", ".");
                    string luacname   = luaname.Replace(".lua", "").Replace(".", "+");
                    string luaMd5Name = CUtils.GetRightFileName(luacname);

                    line = "[\"" + luaMd5Name + "\"] = { size = " + GetAssetbundleSize(luaMd5Name + ".bytes") + ", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", luaMd5Name, luaname);
                }
                EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);

                i++;
            }

            string[] special = new string[] { CUtils.platform, Common.CONFIG_CSV_NAME, Common.CRC32_FILELIST_NAME, Common.CRC32_VER_FILENAME };
            foreach (string p in special)
            {
                name    = EditorUtils.GetAssetBundleName(p);
                nameMd5 = CUtils.GetRightFileName(name);
                string line = "[\"" + nameMd5 + "\"] ={ size = 0, path = \"" + p + "\" },";
                sb.AppendLine(line);
                nameSb.AppendFormat("{0}={1}\r\n", CUtils.GetRightFileName(name), name);
            }

            sb.AppendLine("}");
            string tmpPath = Path.Combine(Application.dataPath, EditorUtils.TmpPath);

            EditorUtils.CheckDirectory(tmpPath);
            EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", "write file to Assets/" + EditorUtils.TmpPath + "Md5Mapping.txt", 0.99f);

            string outPath = Path.Combine(tmpPath, "md5_asset_mapping.txt");

            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(sb.ToString());
            }

            outPath = Path.Combine(tmpPath, "md5_name_mapping.txt");
            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(nameSb.ToString());
            }
            EditorUtility.ClearProgressBar();
            Debug.Log(info + " Complete! Assets/" + EditorUtils.TmpPath + "md5_asset_mapping.txt");
        }