Exemple #1
0
    static void GenerateResZipImp(string rootDir)
    {
        string dirRemove = rootDir + "Assets/StreamingAssets";

        string publishDir = rootDir + "Publish/" +
                            MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
                            + "/";

        // if (PackageWizard.m_wizard)
        // {
        //     publishDir += PackageWizard.m_wizard.version;
        // }

        MyFileUtil.DeleteDir(publishDir);
        MyFileUtil.CreateDir(publishDir);

        List <ResInfo> listResInfo = new List <ResInfo>();

        //----------------------------------------------------//

        List <ZipResConfig> listZipConfig = ZipResConfig.GetConfigList();

        foreach (ZipResConfig zipConfig in listZipConfig)
        {
            //生成Zip资源包
            List <string> fileList = new List <string>();

            if (string.IsNullOrEmpty(zipConfig.resDir) == false)
            {
                string fileDir = rootDir + zipConfig.resDir;

                if (fileDir.Contains("@Platform"))
                {
                    fileDir = fileDir.Replace("@Platform", ResourcesManager.GetPlatformDir());
                }

                if (fileDir.Contains("@Version"))
                {
                    // fileDir = fileDir.Replace("@Version", SDKConfig.GetCurrentVersionResPath().ToLower());
                    fileDir = fileDir.Replace("@Version", "test");
                }

                if (Directory.Exists(fileDir))
                {
                    List <string> ignoreFileTypeList = new List <string>();
                    ignoreFileTypeList.Add(".meta");
                    MyFileUtil.GetFileList(fileDir, ref fileList, zipConfig.listResSuffix, ignoreFileTypeList);
                }
            }

            //特殊文件
            foreach (string specialResPath in zipConfig.listSpecialResPath)
            {
                string newFilePath = rootDir + specialResPath;
                if (File.Exists(newFilePath))
                {
                    fileList.Add(newFilePath);
                }
            }

            if (fileList.Count == 0)
            {
                continue;
            }

            //zip中不记录文件的时间
            string zipResFilePath;
            // if (PackageWizard.m_wizard)
            // {
            //     zipResFilePath = rootDir + "Publish/" +
            //     MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
            //     + "/" + PackageWizard.m_wizard.version + "/" + zipConfig.resZipName;
            // }
            // else
            // {
            zipResFilePath = rootDir + "Publish/" +
                             MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
                             + "/" + zipConfig.resZipName;
            // }
            ZIPTool.CompressFiles(fileList, dirRemove, zipResFilePath, 0, false, true);

            //资源信息
            ResInfo resInfo = new ResInfo();
            resInfo.resName      = zipConfig.resZipName;
            resInfo.resMD5       = MD5Tool.GetByFilePath(zipResFilePath);
            resInfo.resSize      = (int)MyFileUtil.GetFileSize(zipResFilePath);
            resInfo.resRequireID = zipConfig.resRequireID;
            // if (PackageWizard.m_wizard)
            // {
            //     resInfo.resURL = PackageWizard.m_wizard.serverAddress + resInfo.resName;
            // }
            // else
            // {
            resInfo.resURL = resInfo.resName;
            // }

            listResInfo.Add(resInfo);
        }

        //----------------------------------------------------//
        //写到发布目录
        string xmlContent = VersionInfo.SerializeInEditor(listResInfo);
        string xmlFilePath;

        // if (PackageWizard.m_wizard)
        // {
        //     xmlFilePath = rootDir + "Publish/" +
        //     MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)
        //     + "/" + PackageWizard.m_wizard.version + "/VersionInfo.xml";
        // }
        // else
        // {
        xmlFilePath = rootDir + "Publish/" +
                      MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/VersionInfo.xml";
        // }

        File.WriteAllText(xmlFilePath, xmlContent);

        listResInfo.RemoveAll(r => r.resRequireID > 0);
        xmlContent = VersionInfo.SerializeInEditor(listResInfo);
        //写到工程目录
        string xmlFileInProjectPath = rootDir + "Assets/StreamingAssets/Config/" + VersionManager.VersionInfoFilePath + MyFileUtil.EncryptXMLFileSuffix;

        byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(xmlContent);
        data = MyFileUtil.EncryptData(data);
        File.WriteAllBytes(xmlFileInProjectPath, data);
        Debug.Log("生成资源包结束");
    }