当前位置:网站首页>UE5热更新-远端服务器自动下载和版本检测(SimpleHotUpdate)
UE5热更新-远端服务器自动下载和版本检测(SimpleHotUpdate)
2022-07-05 07:23:00 【人宅】
哈喽大家好,我叫人宅,很高兴和大家讲解以上的内容:
热更新插件 SimpleHotUpdate 在使用的时候很多人不知道如何自动下载远端部署好的热更新资源。我也经常远程辅助解决这方面问题,解决多了,发现都是相同问题,这里特此发一篇关于热更新的自动如何部署代码:
只需要将下面的代码复制到自己的工程Source里面:
1.目录结构
以MMOARPG工程为例
2.在自己的项目build.cs下包含SimpleHotUpdate和UMG模块 最好也把Slate 和SlateCore也打开
3.将下面的代码拷贝到自己的代码文件中
UI_HotUpdateMain.h
//Copyright (C) RenZhai.2022.All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "UI_HotUpdateMain.generated.h"
class UTextBlock;
class UProgressBar;
class UVersionControlObject;
enum class EServerVersionResponseType :uint8;
/**
*
*/
UCLASS()
class UUI_HotUpdateMain : public UUserWidget
{
GENERATED_BODY()
UPROPERTY(meta = (BindWidget))
UTextBlock* TipText;
UPROPERTY(meta = (BindWidget))
UTextBlock* VersionName;
UPROPERTY(meta = (BindWidget))
UTextBlock* DownloadSpeedText;
UPROPERTY(meta = (BindWidget))
UTextBlock* DownloadedResourceName;
UPROPERTY(meta = (BindWidget))
UTextBlock* DownloadDataSize;
UPROPERTY(meta = (BindWidget))
UProgressBar* DownLoadProgress;
UPROPERTY()
UVersionControlObject* VersionControlObject;
public:
UUI_HotUpdateMain(const FObjectInitializer& ObjectInitializer);
virtual void NativeConstruct();
virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime);
virtual void NativeDestruct();
private:
UFUNCTION()
void PlayHotUpdateAnim();
UFUNCTION()
void PlayTipAnim();
UFUNCTION()
void Downloading(float InValue, const FString& InName, int32 TotalBytes, int32 BytesReceived);
UFUNCTION()
void CheckVersion(EServerVersionResponseType InType);
void ResetTime();
private:
float PlayAnimTime;//播放动画时间
int32 LastDownloadSize;//上次下载的大小
float DownloadTime;//下载时间记时
bool bReset;//重新捕获下载时间
int32 PreSReceived;//每秒下载多少字节数据
};
UI_HotUpdateMain.cpp
//Copyright (C) RenZhai.2022.All Rights Reserved.
#include "UI_HotUpdateMain.h"
#include "Components/TextBlock.h"
#include "Components/ProgressBar.h"
#include "Object/SimpleHotUpdateObject.h"
//#include "ThreadManage.h"
#include "Kismet/GameplayStatics.h"
#define LOCTEXT_NAMESPACE "UI_HotUpdateMain"
UUI_HotUpdateMain::UUI_HotUpdateMain(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
, PlayAnimTime(10.f)
, LastDownloadSize(0)
, DownloadTime(0.f)
, bReset(false)
, PreSReceived(0)
{
}
void UUI_HotUpdateMain::NativeConstruct()
{
Super::NativeConstruct();
VersionControlObject = UVersionControlObject::CreateObject(UVersionControlObject::StaticClass(), GetWorld());
if (VersionControlObject)
{
VersionControlObject->ProgressDelegate.BindUObject(this, &UUI_HotUpdateMain::Downloading);
VersionControlObject->VersionDelegate.BindUObject(this, &UUI_HotUpdateMain::CheckVersion);
VersionControlObject->InitVersion();
//播放提示动画
PlayTipAnim();
}
}
void UUI_HotUpdateMain::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
Super::NativeTick(MyGeometry, InDeltaTime);
//动画播放
{
PlayAnimTime += InDeltaTime;
if (PlayAnimTime >= 10.f)
{
PlayAnimTime = 0.f;
PlayHotUpdateAnim();
}
}
//时间捕获记录
{
DownloadTime += InDeltaTime;
if (DownloadTime >= 1.f)
{
DownloadTime = 0.f;
ResetTime();
}
}
}
void UUI_HotUpdateMain::NativeDestruct()
{
Super::NativeDestruct();
}
void UUI_HotUpdateMain::Downloading(float InValue, const FString& InName, int32 TotalBytes, int32 BytesReceived)
{
//需要实时显示
if (DownLoadProgress)
{
//打印下载进度
DownLoadProgress->SetPercent(InValue);
}
//每秒执行更新打印显示
if (bReset)
{
bReset = false;
FNumberFormattingOptions FormattingOptions;
FormattingOptions.MaximumFractionalDigits = 1;//保留小数点后1位
if (DownloadedResourceName)
{
//移除后缀
FString ContentName = InName;
ContentName.RemoveFromEnd(FPaths::GetExtension(ContentName, true));
//打印名称
DownloadedResourceName->SetText(FText::FromString(ContentName));
}
if (DownloadDataSize)
{
//打印大小
DownloadDataSize->SetText(
FText::Format(LOCTEXT("Downloading_DownloadDataSize", "{0} / {1}"),
FText::AsMemory(TotalBytes, &FormattingOptions),
FText::AsMemory(BytesReceived, &FormattingOptions)));
}
if (VersionControlObject)
{
bReset = false;
PreSReceived = BytesReceived - LastDownloadSize;
LastDownloadSize = BytesReceived;
DownloadSpeedText->SetText(FText::Format(LOCTEXT("Downloading_DownloadSpeed", "{0} / s"),
FText::AsMemory(PreSReceived, &FormattingOptions)));
//设置版本名称
VersionName->SetText(FText::Format(LOCTEXT("Downloading_Version", "{0}->{1}"),
FText::FromString(VersionControlObject->GetClientVersionName()),
FText::FromString(VersionControlObject->GetServerVersionName())));
}
}
}
void UUI_HotUpdateMain::CheckVersion(EServerVersionResponseType InType)
{
if (InType == EServerVersionResponseType::EQUAL)
{
//GThread::Get()->GetCoroutines().BindLambda(2.f, [&]()
//{
// UGameplayStatics::OpenLevel(GetWorld(), TEXT("Login"));
//});
}
}
void UUI_HotUpdateMain::ResetTime()
{
bReset = true;
}
void UUI_HotUpdateMain::PlayHotUpdateAnim()
{
//if (UWidgetAnimation* InAnim = GetNameWidgetAnimation(TEXT("PlayAnimRenzhai")))
//{
// PlayAnimation(InAnim);
//}
}
void UUI_HotUpdateMain::PlayTipAnim()
{
//if (UWidgetAnimation* InAnim = GetNameWidgetAnimation(TEXT("TipAnim")))
//{
// PlayAnimation(InAnim);
//}
}
#undef LOCTEXT_NAMESPACE
5.创建一个UMG蓝图,把丢失的字体按照格式填充好
填充这些警告的内容
6.用蓝图创建一下,把这个UI贴到视口处
边栏推荐
- Import CV2 prompt importerror: libgl so. 1: Cannot open shared object file: no such file or directory
- Concurrent programming - deadlock troubleshooting and handling
- Import CV2, prompt importerror: libcblas so. 3: cannot open shared object file: No such file or directory
- Simple operation of nixie tube (keil5)
- Basic series of SHEL script (II) syntax + operation + judgment
- ModuleNotFoundError: No module named ‘picamera‘
- (top) pretty girl binary color code portal
- iNFTnews | 喝茶送虚拟股票?浅析奈雪的茶“发币”
- Implementation of one-dimensional convolutional neural network CNN based on FPGA (VIII) implementation of activation layer
- Unconventional ending disconnected from the target VM, address: '127.0.0.1:62635', transport: 'socket‘
猜你喜欢
Ugnx12.0 initialization crash, initialization error (-15)
Altimeter data knowledge point 2
Pytorch has been installed in anaconda, and pycharm normally runs code, but vs code displays no module named 'torch‘
Ethtool principle introduction and troubleshooting ideas for network card packet loss (with ethtool source code download)
PowerManagerService(一)— 初始化
行测--资料分析--fb--高照老师
SD_ CMD_ RECEIVE_ SHIFT_ REGISTER
PostMessage communication
Line test -- data analysis -- FB -- teacher Gao Zhao
The problem of configuring opencv in qt5.13.2 is solved in detail
随机推荐
How to delete the virus of inserting USB flash disk copy of shortcut to
Use of Pai platform
Delayqueue usage and scenarios of delay queue
[vscode] prohibit the pylance plug-in from automatically adding import
Target detection series - detailed explanation of the principle of fast r-cnn
The problem of configuring opencv in qt5.13.2 is solved in detail
[node] NVM version management tool
PostMessage communication
Database SQL practice 3. Find the current salary details of the current leaders of each department and their corresponding department number Dept_ no
arcgis_ spatialjoin
Basic operation of external interrupt (keil5)
纯碱是做什么的?
【obs】x264编码:“buffer_size“
Import CV2, prompt importerror: libcblas so. 3: cannot open shared object file: No such file or directory
Course learning accumulation ppt
Netease to B, soft outside, hard in
2022年PMP项目管理考试敏捷知识点(7)
Negative number storage and type conversion in programs
苏打粉是什么?
PowerManagerService(一)— 初始化