黄金民的个人文档

黄金民的个人文档


LyraGameMode深入理解

<h2>前置学习</h2> <p><a href="https://docs.unrealengine.com/4.27/zh-CN/InteractiveExperiences/Framework/GameMode/" title="GameMode官方文档">GameMode官方文档</a> <a href="https://blog.csdn.net/qq_33500238/article/details/99674576" title="其它资料">其它资料</a></p> <h3>重点总结</h3> <p>GameMode只存在于服务端,不会同步到客户端。需要同步的数据是通过GameState去同步的 GmaeMode主要业务:</p> <ul> <li>现有的玩家和观众人数,以及允许的最大球员和观众人数。</li> <li>玩家怎样进入游戏,其中包括选择生成位置和其他生成/重生行为的规则。</li> <li>是否可以暂停游戏,以及如何开始游戏的暂停。</li> <li>关卡之间的切换,包括游戏是否应该以电影模式启动。</li> </ul> <h4>GameMode创建</h4> <pre><code class="language-cpp">bool UWorld::SetGameMode(const FURL&amp; InURL) { if (!IsNetMode(NM_Client) &amp;&amp; !AuthorityGameMode) { AuthorityGameMode = GetGameInstance()-&gt;CreateGameModeForURL(InURL, this); if( AuthorityGameMode != NULL ) { return true; } else { UE_LOG(LogWorld, Error, TEXT("Failed to spawn GameMode actor.")); return false; } } return false; }</code></pre> <h4>AGameModeBase 关注的类型</h4> <pre><code class="language-cpp">DefaultPawnClass = ADefaultPawn::StaticClass(); PlayerControllerClass = APlayerController::StaticClass(); PlayerStateClass = APlayerState::StaticClass(); GameStateClass = AGameStateBase::StaticClass(); HUDClass = AHUD::StaticClass(); GameSessionClass = AGameSession::StaticClass(); SpectatorClass = ASpectatorPawn::StaticClass(); ReplaySpectatorPlayerControllerClass = APlayerController::StaticClass(); ServerStatReplicatorClass = AServerStatReplicator::StaticClass();</code></pre> <h3>关键调用顺序</h3> <h4>0. AGameModeBase::AGameModeBase</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=2161c8b357c56608e4df1ca7a4bf0ed5&amp;file=file.png" alt="" /></p> <h4>1. AGameModeBase::InitGame</h4> <ul> <li>创建GameSession</li> </ul> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=a7f8dcc3f2ef24cef2b2277902cba8f4&amp;file=file.png" alt="" /></p> <h4>2. AGameModeBase::PreInitializeComponents()</h4> <ul> <li>创建了GameState</li> <li>创建了NetworkManager</li> </ul> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=893b0f6d45cf0f0a815480981adf3122&amp;file=file.png" alt="" /></p> <h5>2.1 AGameModeBase::InitGameState</h5> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=770b26cf391db5b7691c6ab7304244ea&amp;file=file.png" alt="" /></p> <h4>3 AGameModeBase::Login</h4> <ul> <li>创建PlayerController <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=426326649b5ccfb163ff006eda30b5af&amp;file=file.png" alt="" /></li> </ul> <h5>3.1 AGameModeBase::SpawnPlayerController</h5> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=b5dd3552eb2237976a3d3b4b1de96a0b&amp;file=file.png" alt="" /></p> <h6>3.1.1 AGameModeBase::AllowCheats</h6> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=918060f5fe79501f3225674dd21761c6&amp;file=file.png" alt="" /></p> <h4>3.2 AGameModeBase::InitNewPlayer</h4> <ul> <li>注册PlayerControler to GameSession</li> <li>Find a starting spot</li> <li>Set up spectating</li> <li>Init player's name</li> </ul> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=6ef33aad9466168a1142b5112349a063&amp;file=file.png" alt="" /></p> <h5>3.2.1 AGameModeBase::UpdatePlayerStartSpot</h5> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=e8ed7bdb381b9657f83b64fe4084e8cf&amp;file=file.png" alt="" /></p> <h4>3.2.1.1 AGameModeBase::FindPlayerStart_Implementation</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=7e8c16923f4ef4e3c46dfcf78c196b49&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::ShouldSpawnAtStartSpot</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=502517e57aff91d0cd4eb935ea59ad6d&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::ChoosePlayerStart_Implementation</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=84b62ac0bcca00a3e5f22b0e5b27e014&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::MustSpectate_Implementation</h4> <h4>AGameModeBase::ChangeName</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c6e8ab4912500bedab085ec87c6e8357&amp;file=file.png" alt="" /></p> <h4>4. AGameModeBase::PostLogin</h4> <ul> <li>通用PlayerContrller初始化,HUD,声音、语音、地图流式加载、电影模式</li> <li>设置网络带宽</li> <li>设置是不是观察者</li> <li>加入Replay</li> <li>通知GameSession-&gt;PostLogin, PostLogin事件</li> <li>创建PLayer's Pawn,占用起点</li> </ul> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=6d1437806911a4b7205b083f058493f0&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::GenericPlayerInitialization</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=e712bf0b29af618ba53257a7f4914e48&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::InitializeHUDForPlayer_Implementatio</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=f7c86349c5437587827a02a694617fbf&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::UpdateGameplayMuteList</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=e623085811ef326985f01c1492788ff8&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::ReplicateStreamingStatus</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=0d62f33c894bf9ff9f96be2477bc6115&amp;file=file.png" alt="" /></p> <h5>AGameModeBase::ShouldStartInCinematicMode</h5> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=cbed6bfaee6f2022ad45804c7536bfe2&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::DispatchPostLogin</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=40bad14105de2393a319b5ecf288771f&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::HandleStartingNewPlayer_Implementation</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=36ece94498ed020f52d6770115679858&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::MustSpectate_Implementation</h4> <h4>AGameModeBase::PlayerCanRestart_Implementation</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=f71057aad6e813611c82b4ee50a277cc&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::RestartPlayer</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=aa43e0bce2b6edcf3593e147c0d29400&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::SpawnDefaultPawnFor_Implementation</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=21356c90ec6eda88e264ba500d5eeae8&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::SetPlayerDefaults</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=808cceeaa41af2521bff7a996d3ccb9f&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::StartPlay()</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=33440051e94099b4414df4e704f0a374&amp;file=file.png" alt="" /></p> <h4>AGameModeBase::Logout</h4>

页面列表

ITEM_HTML