예제 #1
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();
    }
예제 #2
0
    public static void ApplyMicroPart(bool isMain)
    {
        string    tempPath      = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")) + "/" + ResConfig.FDESASSETBUNDLE;//打包缓存路径
        string    microTempPath = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")).Replace("Assets/StreamingAssets", "FPartPack/Micro/") + ResConfig.FDESASSETBUNDLE;
        string    microPath     = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")).Replace("Assets/StreamingAssets", "FPartPack/Micro/");
        MicroFile micros        = new MicroFile();

        if (isMain)
        {
            string zip = microPath + ResConfig.MicroBundleName + ".zip";
            if (File.Exists(zip))
            {
                string      streamConfig = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", ""));
                FSaveHandle firstData    = FSaveHandle.Create(streamConfig + "/" + ResConfig.STREAMINGASSETSCONFIG, FFilePath.FP_Abs);
                if (!firstData.IsLoad)
                {
                    Debug.LogError("没找到新配置文件:" + streamConfig + "/" + ResConfig.STREAMINGASSETSCONFIG + "操作失败");
                    return;
                }
                BundleManager.StreamConfig firstStreamConfi = new BundleManager.StreamConfig();
                firstData.FromObject(firstStreamConfi);
                if (!string.IsNullOrEmpty(firstStreamConfi.microMD5))
                {
                    Debug.LogError("已经是微端包,无需重复生成");
                    return;
                }

                EditorUtility.DisplayCancelableProgressBar("微端生成中", "正在处理... ", 0);
                List <string> changeFiles = new List <string>();
                FZipTool.UnZip(zip, FEPath.GetDirectoryName(zip), ResConfig.FZIPPASS);
                AssetDatabase.Refresh();
                FSaveHandle msave = FSaveHandle.Create(microTempPath + "/" + ResConfig.MicroBundleName, FFilePath.FP_Abs, FOpenType.OT_Txt);
                if (msave.IsLoad)
                {
                    msave.FromObject(micros);
                    for (int i = 0; i < micros.datas.Count; i++)
                    {
                        var data = micros.datas[i];
                        EditorUtility.DisplayCancelableProgressBar("微端生成中", "正在处理:" + data.bundleName, i / (float)micros.datas.Count);
                        var realyPath = tempPath + "/" + data.bundleName;
                        if (File.Exists(realyPath))
                        {
                            var md5 = FEngineManager.GetMD5HashFromFile(realyPath);
                            if (data.md5 == md5)
                            {
                                File.Delete(realyPath);
                                changeFiles.Add(data.bundleName);
                            }
                        }
                        else
                        {
                            Debug.LogError("文件拷贝失败:" + realyPath);
                        }
                    }

                    //更改配置文件
                    firstStreamConfi.microMD5    = FEngineManager.GetMD5HashFromFile(zip);
                    firstStreamConfi.microsFiles = changeFiles;
                    firstStreamConfi.zipSize     = new System.IO.FileInfo(zip).Length / 1024;
                    firstData.PushObject(firstStreamConfi);
                    firstData.Save();
                    Debug.Log("微端生成成功");
                    EditorUtility.ClearProgressBar();
                }
                else
                {
                    Debug.LogError(ResConfig.MicroBundleName + "微端资源列表没有找到");
                }
            }
            else
            {
                Debug.LogError("微端资源文件没有找到");
            }
        }
        else
        {
            //读取配置文件
            FSaveHandle sd = FSaveHandle.Create(Application.dataPath + "/" + ResConfig.NOPACKPATH, FFilePath.FP_Abs, FOpenType.OT_Binary);
            if (sd.IsLoad)
            {
                List <string>             haveMicros = new List <string>();
                EditorScripts.NoPackAsset nopack     = new EditorScripts.NoPackAsset();
                sd.FromObject(nopack);
                EditorUtility.DisplayCancelableProgressBar("微端资源处理", "正在处理... ", 0);
                for (int i = 0; i < nopack.mlist.Length; i++)
                {
                    var data = nopack.mlist[i];
                    if (PackFileEditor.IsHaveSameWinType(data.type, (int)PackType.micro))
                    {
                        EditorUtility.DisplayCancelableProgressBar("微端资源处理", "正在处理:" + data.bunldName, i / (float)nopack.mlist.Length);
                        //拷贝文件到微端
                        var realyPath = tempPath + "/" + data.bunldName;
                        if (File.Exists(realyPath))
                        {
                            if (!haveMicros.Contains(data.bunldName))
                            {
                                haveMicros.Add(data.bunldName);
                                MicroFile.Data md = new MicroFile.Data();
                                md.bundleName = data.bunldName;
                                md.md5        = FEngineManager.GetMD5HashFromFile(realyPath);
                                micros.datas.Add(md);
                                var    copyPath = microTempPath + "/" + data.bunldName;
                                string dir      = FEPath.GetDirectoryName(copyPath);
                                if (!FEPath.Exists(dir))
                                {
                                    FEPath.CreateDirectory(dir);
                                }
                                if (File.Exists(copyPath))
                                {
                                    File.Copy(realyPath, copyPath, true);
                                }
                                else
                                {
                                    File.Copy(realyPath, copyPath);
                                }
                            }
                        }
                        else
                        {
                            Debug.LogError("文件拷贝失败:" + realyPath);
                        }
                    }
                }

                FSaveHandle msave = FSaveHandle.Create(microTempPath + "/" + ResConfig.MicroBundleName, FFilePath.FP_Abs, FOpenType.OT_Txt | FOpenType.OT_Write);
                msave.PushObject(micros);
                msave.Save();

                EditorUtility.DisplayCancelableProgressBar("微端资源处理", "压缩文件中", 0.3f);

                //打成微包
                FZipTool.ZipDirectory(microTempPath, microPath, ".meta.delete", ResConfig.MicroBundleName);
                //删除压缩前的文件夹
                EditorUtility.ClearProgressBar();
                string beiFen   = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", ""));
                string copyPack = beiFen.Replace("Assets/StreamingAssets", "FTempCopyPack/Micro_" + DateTime.Now.ToString("MM_dd--HH_mm") + ".zip");
                FEPath.CreateDirectory(FEPath.GetDirectoryName(copyPack));
                File.Copy(microPath + "/" + ResConfig.MicroBundleName + ".zip", copyPack);
                Debug.Log("微端文件生成成功");
                AssetDatabase.Refresh();
                System.Diagnostics.Process.Start(microPath + "/");
            }
            else
            {
                Debug.LogError(Application.dataPath + "/" + ResConfig.NOPACKPATH + "没有找到配置文件");
            }
        }
        MyEdior.DeletFile(microTempPath);
    }