上周做了FirstPerson模板的回放系统,本周我主要在主项目中编写回放系统。遇到了很多问题。还没有完全解决。
1)打开Config/DefaultEngine.ini,添加如下语句保存以允许使用DemoNetDriver:
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="DemoNetDriver",DriverClassName="/Script/Engine.DemoNetDriver",DriverClassNameFallback="/Script/Engine.DemoNetDriver")
创建一个父类为MyGameInstance的C++类,命名为
MyGameInstance。打开Visual Studio,先打开 项目名.Build.cs 这个C#文件,添加语句:
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Json" });
然后完成头文件与CPP文件:
//头文件
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "NetworkReplayStreaming.h"
#include "MyGameInstance.generated.h"
USTRUCT(BlueprintType)
struct FS_ReplayInfo
{
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadOnly)
FString ReplayName;
UPROPERTY(BlueprintReadOnly)
FString FriendlyName;
UPROPERTY(BlueprintReadOnly)
FDateTime Timestamp;
UPROPERTY(BlueprintReadOnly)
int32 LengthInMS;
UPROPERTY(BlueprintReadOnly)
bool bIsValid;
FS_ReplayInfo(FString NewName, FString NewFriendlyName, FDateTime NewTimestamp, int32 NewLengthInMS)
{
ReplayName = NewName;
FriendlyName = NewFriendlyName;
Timestamp = NewTimestamp;
LengthInMS = NewLengthInMS;
bIsValid = true;
}
FS_ReplayInfo()
{
ReplayName = "Replay";
FriendlyName = "Replay";
Timestamp = FDateTime::MinValue();
LengthInMS = 0;
bIsValid = false;
}
};
/**
*
*/
UCLASS()
class TAICHIPROJECT_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
/** Start recording a replay from blueprint. ReplayName = Name of file on disk, FriendlyName = Name of replay in UI */
UFUNCTION(BlueprintCallable, Category = "Replays")
void StartRecordingReplayFromBP(FString ReplayName, FString FriendlyName);
/** Start recording a running replay and save it, from blueprint. */
UFUNCTION(BlueprintCallable, Category = "Replays")
void StopRecordingReplayFromBP();
/** Start playback for a previously recorded