Ejemplo n.º 1
0
        private static void CreatFileDependencies()
        {
            List <string> scriptPathList       = new 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 ScriptFolderPath)
            {
                string fullPath = AssetFolder + path;
                scriptPathList.AddRange(ABHelper.GetAllFilesPathInDir(fullPath));
            }
            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));
            }
            CurVersionFileType         = new Dictionary <string, string>();
            CurVersionDependenciesList = new Dictionary <string, List <string> >();
            CurVersionManifestList     = new Dictionary <string, List <string> >();
            CurVersionMd5List          = new Dictionary <string, string>();
            foreach (string path in scriptPathList)
            {
                if (!IsScriptFileRes(path))
                {
                    continue;
                }
                string filePath = path.Replace("\\", "/");
                if (!CurVersionMd5List.ContainsKey(filePath))
                {
                    CurVersionMd5List.Add(filePath, ABHelper.BuildMD5ByFile(filePath));
                }
                if (!CurVersionDependenciesList.ContainsKey(filePath))
                {
                    CurVersionDependenciesList.Add(filePath, new List <string>());
                    CurVersionFileType.Add(filePath, "4");
                }
                CurVersionDependenciesList[filePath].Add(filePath);
            }
            foreach (string path in folderBundlePathList)
            {
                if (!IsNeedFileRes(path))
                {
                    continue;
                }
                string filePath = path.Replace("\\", "/");
                if (!CurVersionMd5List.ContainsKey(filePath))
                {
                    CurVersionMd5List.Add(filePath, ABHelper.BuildMD5ByFile(filePath));
                }

                string filePath2 = ABHelper.GetFileFolderPath(filePath);
                if (!CurVersionDependenciesList.ContainsKey(filePath2))
                {
                    CurVersionDependenciesList.Add(filePath2, new List <string>());
                    CurVersionFileType.Add(filePath2, "0");
                }
                CurVersionDependenciesList[filePath2].Add(filePath);
            }
            foreach (string path in luaPathList)
            {
                if (!path.EndsWith(".lua"))
                {
                    continue;
                }
                string filePath = path.Replace("\\", "/");
                if (!CurVersionMd5List.ContainsKey(filePath))
                {
                    CurVersionMd5List.Add(filePath, ABHelper.BuildMD5ByFile(filePath));
                }
                if (!CurVersionDependenciesList.ContainsKey(filePath))
                {
                    CurVersionDependenciesList.Add(filePath, new List <string>());
                    CurVersionFileType.Add(filePath, "1");
                }
                CurVersionDependenciesList[filePath].Add(filePath);
            }
            foreach (string path in fileBundlePathList)
            {
                if (!IsNeedFileRes(path))
                {
                    continue;
                }
                string   filePath    = path.Replace("\\", "/");
                string[] dependPaths = AssetDatabase.GetDependencies(filePath);
                if (dependPaths.Length > 0)
                {
                    CurVersionDependenciesList.Add(filePath, new List <string>(dependPaths));
                    CurVersionFileType.Add(filePath, "2");
                    foreach (string path1 in dependPaths)
                    {
                        if (!CurVersionMd5List.ContainsKey(path1))
                        {
                            CurVersionMd5List.Add(path1, ABHelper.BuildMD5ByFile(path1));
                        }
                        if (path1.Contains(ResFolder) && filePath != path1)
                        {
                            if (!CurVersionManifestList.ContainsKey(filePath))
                            {
                                CurVersionManifestList.Add(filePath, new List <string>());
                            }
                            CurVersionManifestList[filePath].Add(path1);
                        }
                    }
                }
            }
            foreach (string path in sceneBundlePathList)
            {
                if (!path.EndsWith(".unity"))
                {
                    continue;
                }
                string   filePath    = path.Replace("\\", "/");
                string[] dependPaths = AssetDatabase.GetDependencies(filePath);
                if (dependPaths.Length > 0)
                {
                    CurVersionDependenciesList.Add(filePath, new List <string>(dependPaths));
                    CurVersionFileType.Add(filePath, "3");
                    foreach (string path1 in dependPaths)
                    {
                        if (!CurVersionMd5List.ContainsKey(path1))
                        {
                            CurVersionMd5List.Add(path1, ABHelper.BuildMD5ByFile(path1));
                        }
                        if (path1.Contains(ResFolder) && filePath != path1)
                        {
                            if (!CurVersionManifestList.ContainsKey(filePath))
                            {
                                CurVersionManifestList.Add(filePath, new List <string>());
                            }
                            CurVersionManifestList[filePath].Add(path1);
                        }
                    }
                }
            }

            // 版本所需资源的md5码保存
            ABHelper.WriteMd5File(CurVersionABExportPath + ABHelper.Md5FileName, CurVersionMd5List);
            // 文件的依赖关系
            ABHelper.WriteDependFile(CurVersionABExportPath + ABHelper.DependFileName, CurVersionDependenciesList);
        }