当前位置:网站首页>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贴到视口处
边栏推荐
- [node] differences among NPM, yarn and pnpm
- Concurrent programming - deadlock troubleshooting and handling
- Simple operation of nixie tube (keil5)
- Altimeter data knowledge point 2
- Ggplot2 drawing learning notes in R
- 纯碱是做什么的?
- Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
- Brief description of inux camera (Mipi interface)
- The golang timer uses the stepped pit: the timer is executed once a day
- [software testing] 03 -- overview of software testing
猜你喜欢
Netease to B, soft outside, hard in
iNFTnews | 喝茶送虚拟股票?浅析奈雪的茶“发币”
Chapter 2: try to implement a simple bean container
PostMessage communication
Concurrent programming - deadlock troubleshooting and handling
[software testing] 03 -- overview of software testing
【Node】nvm 版本管理工具
一文揭开,测试外包公司的真实情况
Machine learning Seaborn visualization
IPage can display data normally, but total is always equal to 0
随机推荐
docker安装mysql并使用navicat连接
Using GEE plug-in in QGIS
SD_ CMD_ RECEIVE_ SHIFT_ REGISTER
2022年PMP项目管理考试敏捷知识点(7)
Steps and FAQs of connecting windows Navicat to Alibaba cloud server MySQL
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
Implementation of one-dimensional convolutional neural network CNN based on FPGA (VIII) implementation of activation layer
CADD课程学习(5)-- 构建靶点已知的化合结构(ChemDraw)
公安基础知识--fb
一文揭开,测试外包公司的真实情况
The mutual realization of C L stack and queue in I
ModuleNotFoundError: No module named ‘picamera‘
PHY drive commissioning --- mdio/mdc interface Clause 22 and 45 (I)
GPIO port bit based on Cortex-M3 and M4 with operation macro definition (can be used for bus input and output, STM32, aducm4050, etc.)
I implement queue with C I
目标检测系列——Faster R-CNN原理详解
Database SQL practice 3. Find the current salary details of the current leaders of each department and their corresponding department number Dept_ no
Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
Solve tensorfow GPU modulenotfounderror: no module named 'tensorflow_ core. estimator‘
网易To B,柔外刚中