当前位置: 首页 > news >正文

佛山门户网站建设公司常州高端网站建设公司

佛山门户网站建设公司,常州高端网站建设公司,怎样建设美丽中国?,360关键词排名推广http网络编程在ue5中实现 需求#xff1a;在unreal中实现下载功能#xff0c;输入相关url网址#xff0c;本地文件夹存入相应文件。 一、代码示例 1.Build.cs需要新增Http模块#xff0c;样例如下。 PublicDependencyModuleNames.AddRange(new string[] { Core在unreal中实现下载功能输入相关url网址本地文件夹存入相应文件。 一、代码示例 1.Build.cs需要新增Http模块样例如下。 PublicDependencyModuleNames.AddRange(new string[] { Core, CoreUObject, Engine, InputCore, HTTP });2.RuntimeFilesDownloaderLibrary.h文件 // Fill out your copyright notice in the Description page of Project Settings.#pragma once#include CoreMinimal.h #include UObject/Object.h #include Interfaces/IHttpRequest.h #include RuntimeFilesDownloaderLibrary.generated.hUENUM(BlueprintType, Category Runtime Files Downloader) enum DownloadResult {SuccessDownloading UMETA(DisplayName Success),DownloadFailed UMETA(DisplayName Download failed),SaveFailed UMETA(DisplayName Save failed),DirectoryCreationFailed UMETA(DisplayName Directory creation failed) }; DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnFilesDownloaderProgress, const int32, BytesSent, const int32, BytesReceived, const int32, ContentLength);DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnFilesDownloaderResult, TEnumAsByte DownloadResult , Result);UCLASS() class DOWNLOAD_API URuntimeFilesDownloaderLibrary : public UObject {GENERATED_BODY() public:UPROPERTY(BlueprintAssignable, Category Runtime Files Downloader)FOnFilesDownloaderProgress OnProgress;UPROPERTY(BlueprintAssignable, Category Runtime Files Downloader)FOnFilesDownloaderResult OnResult;UPROPERTY(BlueprintReadOnly, Category Runtime Files Downloader)FString FileURL;UPROPERTY(BlueprintReadOnly, Category Runtime Files Downloader)FString FileSavePath;UFUNCTION(BlueprintCallable, Category Runtime Files Downloader)static URuntimeFilesDownloaderLibrary* CreateDownloader();UFUNCTION(BlueprintCallable, Category Runtime Files Downloader)bool DownloadFile(const FString URL, const FString SavePath, float TimeOut 5); private:void OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived);void OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful); };3.RuntimeFilesDownloaderLibrary.cpp文件 #include RuntimeFilesDownloaderLibrary.h #include HttpModule.h #include Interfaces/IHttpRequest.h #include Interfaces/IHttpResponse.h //创建了一个URuntimeFilesDownloaderLibrary对象并将其添加到根对象防止系统自动回收 URuntimeFilesDownloaderLibrary* URuntimeFilesDownloaderLibrary::CreateDownloader() {URuntimeFilesDownloaderLibrary* Downloader NewObjectURuntimeFilesDownloaderLibrary();Downloader-AddToRoot();return Downloader; }bool URuntimeFilesDownloaderLibrary::DownloadFile(const FString URL, const FString SavePath, float TimeOut) {if (URL.IsEmpty() || SavePath.IsEmpty() || TimeOut 0){return false;}FileURL URL;FileSavePath SavePath;/*ue4.27旧版本弃用下列方法*//*TSharedRefIHttpRequest, ESPMode::ThreadSafe HttpRequest FHttpModule::Get().CreateRequest();*///4.27及以后使用如下方法TSharedPtrIHttpRequest, ESPMode::ThreadSafe HttpRequest FHttpModule::Get().CreateRequest();HttpRequest-SetVerb(GET);HttpRequest-SetURL(FileURL);//HttpRequest-SetTimeout(TimeOut);//监听事件OnProcessRequestComplete绑定OnReady_InternalOnRequestProgress绑定OnProgress_InternalHttpRequest-OnProcessRequestComplete().BindUObject(this, URuntimeFilesDownloaderLibrary::OnReady_Internal);HttpRequest-OnRequestProgress().BindUObject(this, URuntimeFilesDownloaderLibrary::OnProgress_Internal);// Process the requestHttpRequest-ProcessRequest();return true; }//监听事件 void URuntimeFilesDownloaderLibrary::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived) {const FHttpResponsePtr Response Request-GetResponse();if (Response.IsValid()){const int32 FullSize Response-GetContentLength();OnProgress.Broadcast(BytesSent, BytesReceived, FullSize);} }void URuntimeFilesDownloaderLibrary::OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response,bool bWasSuccessful) { RemoveFromRoot();Request-OnProcessRequestComplete().Unbind();if (Response.IsValid() EHttpResponseCodes::IsOk(Response-GetResponseCode()) bWasSuccessful){//IPlatformFile PlatformFile FPlatformFileManager::Get().GetPlatformFile();// FString Path, Filename, Extension;FPaths::Split(FileSavePath, Path, Filename, Extension);//查看文件夹没有则创建文件if (!PlatformFile.DirectoryExists(*Path)){if (!PlatformFile.CreateDirectoryTree(*Path)){OnResult.Broadcast(DirectoryCreationFailed);return;}}// 开启文件写入//通过PlatformFile.OpenWrite()函数打开文件句柄以便将下载的数据写入文件中。函数的参数是一个TCHAR类型的字符串表示文件的路径和文件名。//然后检查句柄是否成功打开。如果句柄成功打开就将HTTP请求响应中的数据通过FileHandle-Write()函数写入到文件中。IFileHandle* FileHandle PlatformFile.OpenWrite(*FileSavePath);if (FileHandle){// FileHandle-Write(Response-GetContent().GetData(), Response-GetContentLength());// delete FileHandle;OnResult.Broadcast(SuccessDownloading);}else{OnResult.Broadcast(SaveFailed);}}else{OnResult.Broadcast(DownloadFailed);} }二、蓝图示例 该蓝图在关卡中调用通过Event Begin Play事件监听行为当按下 按钮创建DOWNLOADER对象并执行下载功能下载时对下载行为进行监听包括RESULTSuccessDownload failedSave failedDirectory creation failed四种下载结果)和以下三个数据信息 · BytesSent 表示已发送的字节数指示已经发送到服务器的字节数。 · BytesReceived 表示已接收的字节数指示已从服务器接收到的字节数。 · FullSize 表示完整内容的长度指示需要下载的文件的总字节数。 最后通过BytesReceived/FullSize计算出百分号数据实现下载进度实时追踪下载完成后RESULT枚举信息输出。 三、效果展示 在蓝图中输入url和save path相关信息time out为响应时间设置。 下载过程实现监听下载完成后输出RESULT枚举类型。 最后本地文件夹成功下载http文件。
http://www.w-s-a.com/news/229899/

相关文章:

  • wordpress建站 云打印昆明 网站设计
  • 太原网站建设设计网站建设策划书(建设前的市场分析)
  • 哪里有制作网站电商新手入门知识
  • 制作网站的后台文昌网站建设 myvodo
  • 网站 购买移动网站制作
  • 南京网站网站建设学校英山做网站多少钱
  • 珠海网站建设网如何注册公司公众号
  • 手机网站页面制作网站怎么做快照
  • asp网站怎么仿站推广软件下载平台
  • 电子商务网站建设期末试题08答案互联网怎么做
  • 规范门户网站的建设和管理办法微信网站开发公司电话
  • 免费行情网站凡客的官网
  • 做网站运营的女生多吗海淀企业网站建设
  • 网站运行环境配置网站建设个一般需要花费多少钱
  • 广西平台网站建设报价wordpress 免费 企业 主题
  • 四川省建设厅职称查询网站辽宁省住房和城乡建设部网站
  • 公司网站后台登陆网站放到云服务器上怎么做
  • 济南 网站定制做网站购买域名
  • 代理分佣后台网站开发怎么用源码做网站视频
  • 天津网站建设招标wordpress七牛图片插件
  • 建设合同施工合同示范文本汕头市网络优化推广平台
  • 网站关键词修改老王搜索引擎入口
  • 那个网站做搬家推广比较好建设部网站办事大厅栏目
  • 做企业销售分析的网站广州网站设计建设
  • 建站流程wordpress怎么开伪静态
  • 服务器不是自己的做违法网站videopro wordpress
  • 北京建网站的公司哪个比较好网站开通告知书
  • 网站负责人 主体负责人黑龙江 建设监理协会网站
  • 手机网站焦点图代码建设工程质量检测网站
  • 墙绘做网站推广有作用没html网页制作用什么软件