当前位置:网站首页>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贴到视口处
边栏推荐
- SD_ CMD_ SEND_ SHIFT_ REGISTER
- 【无标题】
- Import CV2 prompt importerror: libgl so. 1: Cannot open shared object file: no such file or directory
- Idea push project to code cloud
- When jupyter notebook is encountered, erroe appears in the name and is not output after running, but an empty line of code is added downward, and [] is empty
- arcpy. SpatialJoin_ Analysis spatial connection analysis
- I implement queue with C I
- Idea to view the source code of jar package and some shortcut keys (necessary for reading the source code)
- [vscode] search using regular expressions
- Basic operation of external interrupt (keil5)
猜你喜欢
Target detection series - detailed explanation of the principle of fast r-cnn
HDU1231 最大连续子序列(分治or动规or双指针)
CADD课程学习(6)-- 获得已有的虚拟化合物库(Drugbank、ZINC)
Graduation thesis project local deployment practice
剑指 Offer 56 数组中数字出现的次数(异或)
2022 PMP project management examination agile knowledge points (7)
Machine learning Seaborn visualization
2022年PMP项目管理考试敏捷知识点(7)
Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
网易To B,柔外刚中
随机推荐
Reading literature sorting 20220104
二分查找(折半查找)
[tf1] save and load parameters
Pytorch has been installed in anaconda, and pycharm normally runs code, but vs code displays no module named 'torch‘
Microservice registry Nacos introduction
M2dgr slam data set of multi-source and multi scene ground robot
Mathematical analysis_ Notes_ Chapter 8: multiple integral
Mipi interface, DVP interface and CSI interface of camera
(tool use) how to make the system automatically match and associate to database fields by importing MySQL from idea and writing SQL statements
The mutual realization of C L stack and queue in I
Hdu1232 unimpeded project (and collection)
Target detection series - detailed explanation of the principle of fast r-cnn
D2L installation
golang定时器使用踩的坑:定时器每天执行一次
Idea push project to code cloud
Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
I implement queue with C I
PHY drive commissioning --- mdio/mdc interface Clause 22 and 45 (I)
Three body goal management notes
What is soda?