/// <summary> /// 下载完毕 /// </summary> static void OnUpdateOver(HTTPRequest req, HTTPResponse resp) { switch (req.State) { case HTTPRequestStates.Finished: if (resp.IsSuccess) { if (_isUncompress) { ZipTool.Zip(ZipTool.ZipType.UncompressBySevenZipByte, ZipOver, resp.Data); } else { CreateFile(resp.Data); } } else { Debug.LogWarning(string.Format("下载完毕,但是服务器发送了个错误信息: Status Code: {0}-{1} Message: {2}", resp.StatusCode, resp.Message, resp.DataAsText)); } break; case HTTPRequestStates.Error: Debug.LogError("下载遇到错误: " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "无异常")); break; case HTTPRequestStates.Aborted: Debug.LogWarning("请求失效!"); break; case HTTPRequestStates.ConnectionTimedOut: Debug.LogError("连接目标地址超时!"); break; case HTTPRequestStates.TimedOut: Debug.LogError("下载处理超时!"); break; } }
/// <summary> /// 开始压缩打出的场景包 /// </summary> void DoCumpress() { //判断是否有文件夹,没有就创建,否则直接写入会报错 if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } EditorGUILayout.LabelField("开始压缩打包资源:", EditorStyles.boldLabel); if (GUILayout.Button("压缩")) { //将所有打包出来的场景,进行压缩 for (int i = 0; i < Dirs.Count; i++) { DirectoryInfo _dir = new DirectoryInfo(Dirs[i]); if (_dir.Exists) { var _files = _dir.GetFiles("*.unity3d"); for (int j = 0; j < _files.Length; j++) { var _fileName = _files[j].FullName.Replace("\\", "/"); string _name = _fileName.Replace(Application.streamingAssetsPath, ""); string _fullPath = OutputPath + _name; Debug.Log("压缩文件存放路径:" + _fullPath); string _tempDir = Path.GetDirectoryName(_fullPath); if (!Directory.Exists(_tempDir)) { Directory.CreateDirectory(_tempDir); } //将文件进行压缩 ZipTool.Zip(ZipTool.ZipType.CompressBySevenZip, null, _fileName, _fullPath); } } else { EditorUtility.DisplayDialog("提示", "导入文件路径不存在,请导出场景文件", "确定"); return; } } } }
/// <summary> /// 开始导出对应文件 /// </summary> void DoOutputFile(DataTable table, EExprotType type) { if (type == EExprotType.C && string.IsNullOrEmpty(OutputPath)) { EditorUtility.DisplayDialog("提示", "当前不压缩数据的导出路径不存在", "确定"); return; } if (type == EExprotType.C && string.IsNullOrEmpty(OutputPathCompress) && IsNeedCompress) { EditorUtility.DisplayDialog("提示", "当前压缩数据的导出路径不存在", "确定"); return; } if (type == EExprotType.S && string.IsNullOrEmpty(OutputPathServer)) { EditorUtility.DisplayDialog("提示", "当前服务器数据导出路径不存在", "确定"); return; } if (type == EExprotType.C && OutputPath == OutputPathCompress) { EditorUtility.DisplayDialog("提示", "压缩数据路径不能与不压缩数据路径相同", "确定"); return; } int _rowCount = table.Rows.Count; int _column = table.Columns.Count; //开始循环写数据 for (int i = _HEADROWNUM; i < _rowCount; i++) { var _row = table.Rows[i]; for (int j = 0; j < _column; j++) { var _s = table.Rows[1][j].ToString().Trim().ToLower(); switch (type) { case EExprotType.C: if (_s == NOCS || _s == NOC) { continue; } break; case EExprotType.S: if (_s == NOCS || _s == NOS) { continue; } break; default: break; } string _type = table.Rows[3][j].ToString(); if (_type == "string") { WriteData(_type, _row[j].ToString(), uint.Parse(table.Rows[4][j].ToString())); } else { WriteData(_type, _row[j].ToString()); } } } if (type == EExprotType.C && IsExportClient) { //数据写入buff完毕,将buff写入不压缩文件 IOTool.CreateFileBytes(OutputPath + "/" + _TableName + ".bytes", NowBuffer.ToBytes()); } //若是压缩选项,则开始压缩 if (type == EExprotType.C && IsNeedCompress) { ZipTool.Zip(ZipTool.ZipType.CompressBySevenZip, null, OutputPath + "/" + _TableName + ".bytes", OutputPathCompress + "/" + _TableName + ".bytes"); } if (type == EExprotType.S && IsExportServer) { IOTool.CreateFileBytes(OutputPathServer + "/" + _TableName + ".bytes", NowBuffer.ToBytes()); } }