UE5.2 LyraDemo源码阅读笔记(四)

上一篇(三)讲到在模式玩法UI点击Elimination进入淘汰赛模式。

UI选择点击Elimination后,触发蓝图W_HostSessionScreen的HostSession节点,有:

调用这个方法切换关卡后,会调用到LyraGameMode.cpp的

ALyraGameMode::InitGame(...)方法,也就是又开始重走一遍加载关卡相关内容的流程。

一、关于关卡Experience加载流程

1、切换关卡:CommonSessionSubSystem.cpp调用GetWorld()->ServerTravel(PendingTravelURL)切换到淘汰赛关卡。

2、初始化游戏:因为切换关卡,随后重新再触发ALyraGameMode.cpp的ALyraGameMode::InitGame()方法初始化关卡相关的Experience流程。

3、定位关卡ExperienceId:ALyraGameMode::HandleMatchAssignmentIfNotExpectingOne(),查找与当前淘汰赛关卡对应的ExperienceId。

4、设置ExperienceId:ALyraGameMode::OnMatchAssignmentGiven()里对ExperienceId进行赋值。

5、进行加载Experience数据资产:ULyraExperienceManagerComponent::SetCurrentExperience里对CurrentExperience赋值的同时,因为它设置了UPROPERTY(ReplicatedUsing=OnRep_CurrentExperience),所以对它进行赋值时会调用同步方法OnRep_CurrentExperience::OnRep_CurrentExperience进行资源加载。

6、初始化Experience数据资产:加载完成后会调用ULyraExperienceManagerComponent::OnExperienceLoadComplete(),对Experience里带的插件进行加载。

代码 ULyraExperienceManagerComponent.cpp

cpp 复制代码
void ULyraExperienceManagerComponent::OnExperienceFullLoadCompleted()
{
...
	auto ActivateListOfActions = [&Context](const TArray<UGameFeatureAction*>& ActionList)
	{
		for (UGameFeatureAction* Action : ActionList)
		{
			if (Action != nullptr)
			{
				//@TODO: The fact that these don't take a world are potentially problematic in client-server PIE
				// The current behavior matches systems like gameplay tags where loading and registering apply to the entire process,
				// but actually applying the results to actors is restricted to a specific world
				Action->OnGameFeatureRegistering();
				Action->OnGameFeatureLoading();
				Action->OnGameFeatureActivating(Context);
			}
		}
	};
	...
}

7、初始化Experience的插件列表:插件加载完成后,调用ULyraExperienceManagerComponent::OnExperienceFullLoadCompleted()这里会连续对插件里的Action列表进行注册、加载、激活。随后发出通知OnExperienceLoaded.Broadcast(CurrentExperience)。

8、生成玩家Pawn:Experience加载完成后发出通知后,触发LyraGameMode::InitGameState注册的方法ALyraGameMode::OnExperienceLoaded(const ULyraExperienceDefinition* CurrentExperience),接着就在这个方法里调用RestartPlayer(PC)生成对应的玩家实体。

二、关于关卡Experience内容

B_ShooterGame_Elimination的定义里包含了要用到的插件和Action集合。

这里会启用一个叫ShooterCore的插件。插件了除了状态,同时也定义了Action的集合

整个游戏的玩法功能,都在这个Experience定义的Action里的模块了,不同类型的Action会把这些模块功能一个个组合到游戏里,形成整体的游戏功能。

相关推荐
im_AMBER41 分钟前
CSS 01【基础语法学习】
前端·css·笔记·学习
摇滚侠42 分钟前
Spring Boot 3零基础教程,深度理解 Spring Boot 自动配置原理,笔记11
spring boot·笔记·后端
fanstering1 小时前
腾讯混元P3-SAM: Native 3D Part Segmentation
笔记·学习·3d·点云
im_AMBER2 小时前
数据结构 05 栈和队列
数据结构·笔记·学习
报错小能手2 小时前
linux学习笔记(31)网络编程——TCP time_wait机制
linux·笔记·学习
思成不止于此3 小时前
软考中级软件设计师备考指南(四):I/O 技术、安全与可靠性 —— 综合应用篇
网络·笔记·学习·信息安全·总线系统·i/o 技术·可靠性计算
聪明的笨猪猪4 小时前
Java Redis “核心应用” 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
聪明的笨猪猪4 小时前
Java Redis “底层结构” 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
岑梓铭6 小时前
考研408《计算机组成原理》复习笔记,第七章(1)——I/O接口
笔记·考研·408·计算机组成原理·计组
摇滚侠8 小时前
Spring Boot 3零基础教程,IOC容器中组件的注册,笔记08
spring boot·笔记·后端