当前位置:网站首页>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贴到视口处
边栏推荐
- PostMessage communication
- Mipi interface, DVP interface and CSI interface of camera
- Light up the running light, rough notes for beginners (1)
- 苏打粉是什么?
- Unity ugui how to match and transform coordinates between different UI panels or uis
- Rough notes of C language (1)
- C#学习笔记
- 并查集理论讲解和代码实现
- 【无标题】
- Unconventional ending disconnected from the target VM, address: '127.0.0.1:62635', transport: 'socket‘
猜你喜欢
Steps and FAQs of connecting windows Navicat to Alibaba cloud server MySQL
HDU1231 最大连续子序列(分治or动规or双指针)
SD_ CMD_ SEND_ SHIFT_ REGISTER
SOC_ SD_ DATA_ FSM
Basic series of SHEL script (III) for while loop
Rough notes of C language (1)
[vscode] prohibit the pylance plug-in from automatically adding import
(tool use) how to make the system automatically match and associate to database fields by importing MySQL from idea and writing SQL statements
Graduation thesis project local deployment practice
[idea] efficient plug-in save actions to improve your work efficiency
随机推荐
SOC_ SD_ CMD_ FSM
D2L installation
Three body goal management notes
The golang timer uses the stepped pit: the timer is executed once a day
U-boot initialization and workflow analysis
selenium 元素定位
Microservice registry Nacos introduction
Matrix and TMB package version issues in R
Powermanagerservice (I) - initialization
Unconventional ending disconnected from the target VM, address: '127.0.0.1:62635', transport: 'socket‘
[software testing] 05 -- principles of software testing
Delayqueue usage and scenarios of delay queue
Using GEE plug-in in QGIS
Use of Pai platform
[software testing] 06 -- basic process of software testing
Line test -- data analysis -- FB -- teacher Gao Zhao
2022.06.27_ One question per day
Word import literature -mendeley
Concurrent programming - deadlock troubleshooting and handling
CADD课程学习(5)-- 构建靶点已知的化合结构(ChemDraw)