|
对一般联网功能的撑持。虚幻引擎中适用于Lyra示例游戏的通用用户插件 | 虚幻引擎5.0文档 (unrealengine.com)
下载与配置
- 下载源码,获取Plugins/CommonUser目录
- 新建空的c++项目,复制张贴CommonUser目录
- 点击.uproject启动编纂器,编纂-插件-看到CommonUser已经启动,再转到c++编纂成功,先c++编译会报错。右键.uproject-生成files-在vs项目生成Plugins目录
- 在线处事是试验性的,交换插件以使用新接口,改削CommonUser.Build.cs,将bUseOnlineSubsystemV1布尔值更改为false,然后找到游戏的Config/DefaultEngine.ini配置文件,添加以下行,这将启用使用新接口时所需的版本依赖项。
- [/Script/Engine.OnlineEngineInterface]
- bUseOnlineServicesV2=true
复制代码
- 要使用EOS在线处事,你需要在包含[OnlineSubsystemEOS]小节的配置文件中禁用 Epic在线处事(EOS)在线子系统。例如,在 Lyra/Config/Custom/EOS/DefaultEngine.ini 文件中,你应该将bEnabled布尔值设置为 false。
- [OnlineSubsystemEOS]
- bEnabled=false
复制代码 Lyra中的使用示例
CommonGameInstance,以集成CommonUser和CommonUI插件的功能- #include ”CommonSessionSubsystem.h” //父类是UGameInstanceSubsystem
- #include ”CommonUserSubsystem.h” //父类是UGameInstanceSubsystem
- void UCommonGameInstance::Init()
- {
- Super::Init();
- // After subsystems are initialized, hook them together
- FGameplayTagContainer PlatformTraits = ICommonUIModule::GetSettings().GetPlatformTraits();
- UCommonUserSubsystem* UserSubsystem = GetSubsystem<UCommonUserSubsystem>();
- if (ensure(UserSubsystem))
- {
- UserSubsystem->SetTraitTags(PlatformTraits);
- UserSubsystem->OnHandleSystemMessage.AddDynamic(this, &UCommonGameInstance::HandleSystemMessage);
- UserSubsystem->OnUserPrivilegeChanged.AddDynamic(this, &UCommonGameInstance::HandlePrivilegeChanged);
- }
- UCommonSessionSubsystem* SessionSubsystem = GetSubsystem<UCommonSessionSubsystem>();
- if (ensure(SessionSubsystem))
- {
- SessionSubsystem->OnUserRequestedSessionEvent.AddUObject(this, &UCommonGameInstance::OnUserRequestedSession);
- }
- }
复制代码 LyraFrontEndStateComponent,直接从源代码访谒CommonUser子系统,在显示主菜单(W_LyraFrontEnd)之前,系统会使用CommonUI显示特定于平台的按”开始”(Press Start)画面(W_LyraStartup** ),而此类就是这个逻辑的一部门。- #include ”CommonSessionSubsystem.h”
- #include ”CommonUserSubsystem.h”
- #include ”CommonUserTypes.h”
- void ULyraFrontendStateComponent::BeginPlay()
- {
- Super::BeginPlay();
- // Listen for the experience load to complete
- AGameStateBase* GameState = GetGameStateChecked<AGameStateBase>();
- ULyraExperienceManagerComponent* ExperienceComponent = GameState->FindComponentByClass<ULyraExperienceManagerComponent>();
- check(ExperienceComponent);
- // This delegate is on a component with the same lifetime as this one, so no need to unhook it in
- ExperienceComponent->CallOrRegister_OnExperienceLoaded_HighPriority(FOnLyraExperienceLoaded::FDelegate::CreateUObject(this, &ThisClass::OnExperienceLoaded));
- }
- void ULyraFrontendStateComponent::OnExperienceLoaded(const ULyraExperienceDefinition* Experience)
- {
- FControlFlow& Flow = FControlFlowStatics::Create(this, TEXT(”FrontendFlow”))
- .QueueStep(TEXT(”Wait For User Initialization”), this, &ThisClass::FlowStep_WaitForUserInitialization)
- .QueueStep(TEXT(”Try Show Press Start Screen”), this, &ThisClass::FlowStep_TryShowPressStartScreen)
- .QueueStep(TEXT(”Try Join Requested Session”), this, &ThisClass::FlowStep_TryJoinRequestedSession)
- .QueueStep(TEXT(”Try Show Main Screen”), this, &ThisClass::FlowStep_TryShowMainScreen);
- Flow.ExecuteFlow();
- FrontEndFlow = Flow.AsShared();
- }
复制代码 W_LyraStartup -来自目录UI/Menu等多个控件直接访谒CommonUserSubsystem并使用函数或异步节点来措置用户操作。-事件触发是点击开始
LyraUserFacingExperienceDefinition类描述了如何使用多玩家FPS的尺度菜单选项启动游戏会话。它由W_HostSessionScreen等控件用于创建会话描述,以传递到CommonSessionSubsystem中来托管或插手游戏会话。- #include ”CommonSessionSubsystem.h”
- #include UE_INLINE_GENERATED_CPP_BY_NAME(LyraUserFacingExperienceDefinition)
- UCommonSession_HostSessionRequest* ULyraUserFacingExperienceDefinition::CreateHostingRequest() const
- {
- const FString ExperienceName = ExperienceID.PrimaryAssetName.ToString();
- const FString UserFacingExperienceName = GetPrimaryAssetId().PrimaryAssetName.ToString();
- UCommonSession_HostSessionRequest* Result = NewObject<UCommonSession_HostSessionRequest>();
- Result->OnlineMode = ECommonSessionOnlineMode::Online;
- Result->bUseLobbies = true;
- Result->MapID = MapID;
- Result->ModeNameForAdvertisement = UserFacingExperienceName;
- Result->ExtraArgs = ExtraArgs;
- Result->ExtraArgs.Add(TEXT(”Experience”), ExperienceName);
- Result->MaxPlayerCount = MaxPlayerCount;
- if (bRecordReplay)
- {
- Result->ExtraArgs.Add(TEXT(”DemoRec”), FString());
- }
- return Result;
- }
复制代码 W_HostSessionScreen来自目录UI/Menu/Experiences-事件触发是选中会话
Lyra Starter Game旨在作为Epic在线处事(EOS)子系统的正常运作例子。默认情况下,Lyra使用Null子系统,仅在编纂器中或局域网上撑持多玩家。要启用对EOS的撑持,你可以在创建打包版本时使用LyraGameEOS方针,或将以下选项添加到你的命令行:这将从你的 c:Lyra/Config/Custom/EOS 目录加载特定于EOS的配置文件。这些配置文件应该改削为使用特定于你的项目的EOS标识符。
实际使用 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|