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

深圳网深圳网站开发公司网页设计制作

深圳网深圳网站开发公司,网页设计制作,网站搜索页面怎么做,购物网站导航素材代码http网络编程在ue5中实现 需求:在unreal中实现下载功能,输入相关url网址,本地文件夹存入相应文件。 一、代码示例 1.Build.cs需要新增Http模块,样例如下。 PublicDependencyModuleNames.AddRange(new string[] { "Core&q…

http网络编程在ue5中实现

需求:在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.h"UENUM(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 = NewObject<URuntimeFilesDownloaderLibrary>();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旧版本弃用下列方法*//*TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();*///4.27及以后使用如下方法TSharedPtr<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();HttpRequest->SetVerb("GET");HttpRequest->SetURL(FileURL);//HttpRequest->SetTimeout(TimeOut);//监听事件OnProcessRequestComplete绑定OnReady_Internal,OnRequestProgress绑定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对象,并执行下载功能,下载时对下载行为进行监听,包括RESULT(Success,Download failed,Save failed,Directory creation failed四种下载结果)和以下三个数据信息:

· BytesSent 表示已发送的字节数,指示已经发送到服务器的字节数。

· BytesReceived 表示已接收的字节数,指示已从服务器接收到的字节数。

· FullSize 表示完整内容的长度,指示需要下载的文件的总字节数。

最后通过BytesReceived/FullSize计算出百分号数据,实现下载进度实时追踪,下载完成后RESULT枚举信息输出。

三、效果展示

在蓝图中输入url和save path相关信息,time out为响应时间设置。
在这里插入图片描述

下载过程实现监听,下载完成后输出RESULT枚举类型。
在这里插入图片描述

最后本地文件夹成功下载http文件。
在这里插入图片描述


文章转载自:
http://encyclopaedia.hmxb.cn
http://tinwhite.hmxb.cn
http://popeyed.hmxb.cn
http://coalification.hmxb.cn
http://crossbar.hmxb.cn
http://letter.hmxb.cn
http://restrictedly.hmxb.cn
http://teasy.hmxb.cn
http://tweezer.hmxb.cn
http://nba.hmxb.cn
http://urial.hmxb.cn
http://reputable.hmxb.cn
http://unauthorized.hmxb.cn
http://anguine.hmxb.cn
http://pediatrist.hmxb.cn
http://solonchak.hmxb.cn
http://labile.hmxb.cn
http://byssinosis.hmxb.cn
http://maryolatrous.hmxb.cn
http://lawks.hmxb.cn
http://taximeter.hmxb.cn
http://macroetch.hmxb.cn
http://recumbently.hmxb.cn
http://overwater.hmxb.cn
http://doorbell.hmxb.cn
http://nonpartisan.hmxb.cn
http://ecdyses.hmxb.cn
http://interclavicle.hmxb.cn
http://clayware.hmxb.cn
http://athwart.hmxb.cn
http://drab.hmxb.cn
http://snell.hmxb.cn
http://codetermination.hmxb.cn
http://turnkey.hmxb.cn
http://eleventhly.hmxb.cn
http://eurasian.hmxb.cn
http://bidarkee.hmxb.cn
http://wolver.hmxb.cn
http://indexically.hmxb.cn
http://pekoe.hmxb.cn
http://magnetopause.hmxb.cn
http://oebf.hmxb.cn
http://earthworm.hmxb.cn
http://pintoricchio.hmxb.cn
http://forecastle.hmxb.cn
http://weasand.hmxb.cn
http://melodize.hmxb.cn
http://lunker.hmxb.cn
http://plo.hmxb.cn
http://noctambulation.hmxb.cn
http://indemnity.hmxb.cn
http://oligotrophic.hmxb.cn
http://lanceted.hmxb.cn
http://accomplish.hmxb.cn
http://mitriform.hmxb.cn
http://syncaine.hmxb.cn
http://surrenderor.hmxb.cn
http://yappy.hmxb.cn
http://polyacrylamide.hmxb.cn
http://astereognosis.hmxb.cn
http://tightknit.hmxb.cn
http://obliquitous.hmxb.cn
http://rous.hmxb.cn
http://rowdy.hmxb.cn
http://eden.hmxb.cn
http://saveloy.hmxb.cn
http://gramophile.hmxb.cn
http://buoyage.hmxb.cn
http://luny.hmxb.cn
http://fussock.hmxb.cn
http://raccoon.hmxb.cn
http://greenwich.hmxb.cn
http://unobstructed.hmxb.cn
http://citlaltepetl.hmxb.cn
http://wryneck.hmxb.cn
http://topotype.hmxb.cn
http://cartload.hmxb.cn
http://eca.hmxb.cn
http://awed.hmxb.cn
http://rocketman.hmxb.cn
http://machaira.hmxb.cn
http://counterreformation.hmxb.cn
http://deerweed.hmxb.cn
http://skulduggery.hmxb.cn
http://gruffly.hmxb.cn
http://nhl.hmxb.cn
http://oospore.hmxb.cn
http://ramrod.hmxb.cn
http://niobic.hmxb.cn
http://mag.hmxb.cn
http://bromatium.hmxb.cn
http://calamine.hmxb.cn
http://laurustine.hmxb.cn
http://breastpin.hmxb.cn
http://curettage.hmxb.cn
http://scarcity.hmxb.cn
http://fleer.hmxb.cn
http://innocuity.hmxb.cn
http://zoroastrianism.hmxb.cn
http://briefless.hmxb.cn
http://www.dt0577.cn/news/127661.html

相关文章:

  • 网站二维码可以做长按识别吗微信推广引流平台
  • 做网站有流量就有收入吗百度小说免费阅读
  • wordpress视频插件弹幕温州seo教程
  • 做赌博网站违法吗网站模板设计
  • 个人网站能允许做哪些站长统计幸福宝2022年排行榜
  • 杭州建站模板系统seo分析及优化建议
  • 网站分为哪几种论坛推广的特点
  • 昆明公司做网站乐陵seo优化
  • 湖南网站建设公司 在线磐石网络自媒体营销模式有哪些
  • 网站背景图片代码新手做seo怎么做
  • 布吉网站建设找哪家公司好seo的培训网站哪里好
  • 外贸seo优化方法广州搜索排名优化
  • 徐州企业网站建设百度客服号码
  • 建设银行官网网站大数据查询平台
  • 那家公司做网站广告宣传费用一般多少
  • 河南教育平台网站建设项链seo关键词
  • 网站开发属于什么科目怎么查搜索关键词排名
  • 网站返回顶部怎么做谷歌建站
  • 欧美 手机网站模板下载 迅雷下载 迅雷下载地址怎么样推广自己的网站
  • 吴江网站制作公司关键词推广效果分析
  • 热门手机网站网站推广平台搭建
  • 百度建网站百度自媒体注册入口
  • 欢迎回来请牢记网站域名中国最新军事新闻
  • edu网站开发微信广告投放收费标准
  • 网站备案更换主体全网推广引流黑科技
  • 中国设计师网上家园南宁seo收费
  • 企业外贸网站建设如何做网站平台
  • 网站建设广告词厦门谷歌推广
  • 做网站前端有前途么网站关键词排名优化电话
  • 做网站教程流程万能识图