示例#1
0
 private static int GetResType(BundleManager.StreamConfig.NormalFile file)
 {
     if (file.resType == ResConfig.FZIPNAMEEX)
     {
         return((int)BundleManager.FResFileType.FT_Zip);
     }
     if (file.resType == ".unity3d" || file.resType == ".manifest" || file.resType == ".meta")
     {
         return((int)BundleManager.FResFileType.FT_Unity);
     }
     else if (string.IsNullOrEmpty(file.path))
     {
         return((int)BundleManager.FResFileType.FT_Null);
     }
     return((int)BundleManager.FResFileType.FT_F);
 }
示例#2
0
    //OperationType 0 解压,1压缩,2不处理
    public static void CreateConfig(string stream, BundleManager.StreamConfig copyStream, int OperationType)
    {
        long   fileSize       = 0;
        string streamTempPath = stream + "/";
        string streamingPath  = streamTempPath + ResConfig.STREAMINGASSETSCONFIG;

        EditorUtility.DisplayCancelableProgressBar("打包资源", "正在处理 " + stream, 0.3f);
        string unKey = ".meta";

        if (OperationType == 2)
        {
            if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS)
            {
                OperationType = 1;
                unKey         = ".meta.delete.unity3d.manifest";
            }
        }
        if (OperationType != 2)
        {
            //插入压缩,解压流程
            for (int i = 0; i < mZipFilesName.Count; i++)
            {
                string pathFile = streamTempPath + mZipFilesName[i];
                string zipDir   = FEPath.GetDirectoryName(pathFile) + "/";
                if (OperationType == 1)
                {
                    if (FEPath.Exists(pathFile))
                    {
                        //string unKey = ".meta";//: ".meta.delete.unity3d.manifest";
                        string outPath = FZipTool.ZipDirectory(pathFile, zipDir, unKey);
                        //删除压缩前的文件夹
                        if (unKey == ".meta")
                        {
                            MyEdior.DeletFile(pathFile);
                        }
                        fileSize += new System.IO.FileInfo(outPath).Length / 1024;
                    }
                }
                else
                {
                    pathFile += ResConfig.FZIPNAMEEX;
                    if (File.Exists(pathFile))
                    {
                        FZipTool.UnZip(pathFile, zipDir, ResConfig.FZIPPASS);
                        //删除解压前的文件夹
                        File.Delete(pathFile);
                    }
                }
            }
        }

        AssetDatabase.Refresh();

        BundleManager.StreamConfig streamConfig = new BundleManager.StreamConfig();
        List <string>      fileList             = new List <string>();
        string             keyStream            = "/" + FEPath.GetFileNameWithoutExtension(FEPath.GetDirectoryName(streamTempPath)) + "/";
        SelectPrefabEditor spe = new SelectPrefabEditor("", keyStream, "", true);

        for (int i = 0; i < spe.tempAllStrs.Length; i++)
        {
            string path = spe.tempAllStrs[i];
            if (File.Exists(path) && path.IndexOf(F_NOCOPYSTREAM) == -1 && (path.IndexOf("Assembly-CSharp") == -1))
            {
                int pos = path.IndexOf(keyStream);
                fileList.Add(path.Substring(pos + keyStream.Length));
            }
        }

        if (fileList.Count != 0)
        {
            for (int index = 0; index < fileList.Count; index++)
            {
                string fileName  = fileList[index];
                var    normaFile = new BundleManager.StreamConfig.NormalFile();
                int    pathPos   = fileName.LastIndexOf("/");
                string pathFile  = "";
                if (pathPos != -1)
                {
                    pathFile = fileName.Substring(0, pathPos);
                }
                normaFile.path     = pathFile;
                normaFile.fileName = fileName;
                normaFile.md5      = FEngineManager.GetMD5HashFromFile(streamTempPath + fileName);
                normaFile.resType  = FEPath.GetExtension(fileName);
                normaFile.FileType = GetResType(normaFile);// (normaFile.resType == ResConfig.FZIPNAMEEX);
                streamConfig.fileDatas.Add(normaFile);
            }
        }

        ScriptsTime.Debug("创建StreamingConfig完成");

        streamConfig.IsBackDownMicro = copyStream.IsBackDownMicro;
        streamConfig.versionId       = copyStream.versionId;
        streamConfig.CustomConfig    = copyStream.CustomConfig;
        streamConfig.zipSize         = fileSize;

        FSaveHandle sd = FSaveHandle.Create(streamingPath, FFilePath.FP_Abs, FOpenType.OT_Write);

        sd.PushObject(streamConfig);
        sd.Save();
        EditorUtility.ClearProgressBar();
    }