Ejemplo n.º 1
0
        private static void CreatVersionTxt()
        {
            // 版号文件
            string fileUrl = CreatFileUrlMd5(ABHelper.VersionNumFileName);

            ABHelper.WriteVersionNumFile(CurVersionABExportPath + fileUrl, ABHelper.VersionNumCombine(TheVersionNum[0], TheVersionNum[1], CurVersionNum.ToString(), TheVersionNum[3]));
            // ab的依赖文件
            fileUrl = CreatFileUrlMd5(ABHelper.ManifestFileName);
            ABHelper.WriteManifestFile(CurVersionABExportPath + fileUrl, ResFolder, CurVersionManifestList);
            // 创建版本文件
            CurVersionList = ABHelper.ReadVersionFile(PlatformABExportPath + "/" + (CurVersionNum - 1) + "/" + ABHelper.VersionFileName);
            List <string> filePaths = ABHelper.GetAllFilesPathInDir(CurVersionABExportPath);

            foreach (string path in filePaths)
            {
                if (path.EndsWith(".manifest"))
                {
                    continue;
                }
                string path2 = path.Replace("\\", "/").Replace(CurVersionABExportPath, "").ToLower();
                if (path2.Equals(CurVersionNum.ToString()) || path2.Equals(ABHelper.DependFileName) || path2.Equals(ABHelper.Md5FileName))
                {
                    continue;
                }

                string value = CurVersionFileUrlMd5[path2].ToLower();
                if (CurVersionList.ContainsKey(value))
                {
                    CurVersionList.Remove(value);
                }
                CurVersionList.Add(value, new List <string>()
                {
                    ABHelper.BuildMD5ByFile(path), CurVersionNum.ToString(), ABHelper.FileSize(path).ToString(), path2
                });
            }
            ABHelper.WriteVersionFile(CurVersionABExportPath + ABHelper.VersionFileName, CurVersionList);
        }
Ejemplo n.º 2
0
        private static void CreatPacker(BuildTarget platform)
        {
            ClearAssetBundlesName();
            AssetDatabase.Refresh();

            CurVersionManifestList = new Dictionary <string, List <string> >();
            List <string> folderBundlePathList = new List <string>();
            List <string> fileBundlePathList   = new List <string>();
            List <string> sceneBundlePathList  = new List <string>();
            List <string> luaPathList          = new List <string>();

            foreach (string path in BundleFolderPath)
            {
                string fullPath = ResFolder + path;
                folderBundlePathList.AddRange(ABHelper.GetAllFilesPathInDir(fullPath));
            }
            foreach (string path in BundleFilePath)
            {
                string fullPath = ResFolder + path;
                fileBundlePathList.AddRange(ABHelper.GetAllFilesPathInDir(fullPath));
            }
            foreach (string path in BundleScenePath)
            {
                string fullPath = AssetFolder + path;
                sceneBundlePathList.AddRange(ABHelper.GetAllFilesPathInDir(fullPath));
            }
            foreach (string path in BundleLuaPath)
            {
                string fullPath = AssetFolder + path;
                luaPathList.AddRange(ABHelper.GetAllFilesPathInDir(fullPath));
            }

            foreach (string path in folderBundlePathList)
            {
                if (!IsNeedFileRes(path))
                {
                    continue;
                }
                // "Assets/Resources/UI/Tips/Tips.bytes"
                string assetPath = path.Replace("\\", "/");
                string abName    = ABHelper.GetFileFolderPath(assetPath.Replace(ResFolder, "")) + ".ab";
                AssetImporter.GetAtPath(assetPath).assetBundleName = CreatFileUrlMd5(abName);
            }
            foreach (string path in fileBundlePathList)
            {
                if (!IsNeedFileRes(path))
                {
                    continue;
                }
                string assetPath = path.Replace("\\", "/");
                string abName    = ABHelper.GetFileFullPathWithoutFtype(assetPath.Replace(ResFolder, "")) + ".ab";
                AssetImporter.GetAtPath(assetPath).assetBundleName = CreatFileUrlMd5(abName);

                // 依赖文件
                string[] dependPaths = AssetDatabase.GetDependencies(assetPath);
                if (dependPaths.Length > 0)
                {
                    foreach (string path1 in dependPaths)
                    {
                        if (path1.Contains(ResFolder) && assetPath != path1)
                        {
                            assetPath = assetPath.Replace(ResFolder, "");
                            if (!CurVersionManifestList.ContainsKey(assetPath))
                            {
                                CurVersionManifestList.Add(assetPath, new List <string>());
                            }
                            CurVersionManifestList[assetPath].Add(path1.Replace(ResFolder, ""));
                        }
                    }
                }
            }
            foreach (string path in sceneBundlePathList)
            {
                if (!path.EndsWith(".unity"))
                {
                    continue;
                }
                string assetPath = path.Replace("\\", "/");
                string abName    = ABHelper.GetFileFullPathWithoutFtype(assetPath.Replace(ResFolder, "") + ".ab");
                AssetImporter.GetAtPath(assetPath).assetBundleName = CreatFileUrlMd5(abName);

                // 依赖文件
                string[] dependPaths = AssetDatabase.GetDependencies(assetPath);
                if (dependPaths.Length > 0)
                {
                    foreach (string path1 in dependPaths)
                    {
                        if (path1.Contains(ResFolder) && assetPath != path1)
                        {
                            assetPath = assetPath.Replace(AssetFolder, "");
                            if (!CurVersionManifestList.ContainsKey(assetPath))
                            {
                                CurVersionManifestList.Add(assetPath, new List <string>());
                            }
                            CurVersionManifestList[assetPath].Add(path1.Replace(ResFolder, ""));
                        }
                    }
                }
            }
            foreach (string path in luaPathList)
            {
                if (!path.EndsWith(".lua"))
                {
                    continue;
                }
                string filePath = path.Replace("\\", "/");
                CopyLuaFiles(filePath);
            }

            System.GC.Collect();
            BuildPipeline.BuildAssetBundles(PlatformABExportPath, BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle, platform);

            ClearAssetBundlesName();
            AssetDatabase.Refresh();

            // ab的依赖文件
            string fileUrl = CreatFileUrlMd5(ABHelper.ManifestFileName);

            ABHelper.WriteManifestFile(PlatformABExportPath + "/" + fileUrl, CurVersionManifestList);

            // 删除不用的manifest
            List <string> allFiles = ABHelper.GetAllFilesPathInDir(PlatformABExportPath);

            foreach (string path in allFiles)
            {
                if (path.EndsWith(".manifest"))
                {
                    File.Delete(path);
                }
                if (ABHelper.GetFileNameWithoutSuffix(path.Replace("\\", "/")) == PlatformName)
                {
                    File.Delete(path);
                }
            }

            // 写入文件
            StringBuilder txt = new StringBuilder();

            foreach (var pair in CurVersionFileUrlMd5)
            {
                txt.Append(pair.Value + ":" + pair.Key + "\r");
            }
            ABHelper.WriteFileByBytes(PlatformABExportPath + "/" + ABHelper.VersionFileName, Encoding.UTF8.GetBytes(txt.ToString().TrimEnd().ToLower()));
        }