美文网首页
虚幻 Unreal Engine 4 Gameplay Fram

虚幻 Unreal Engine 4 Gameplay Fram

作者: 珏_Gray | 来源:发表于2018-12-28 17:30 被阅读0次

参考阅读:https://www.tomlooman.com/ue4-gameplay-framework/
文件路径:
\Engine\Source\Runtime\Engine\Classes\GameFramework\PlayerController.h

描述


by Tom

The primary class for a player, receiving the input of the user. A PlayerController itself is not visually shown in the environment, instead it will ‘Possess’ a Pawn instance which defines the visual and physical representation of that player in the world. During gameplay a player may possess a number of different pawns (eg. a vehicle, or a fresh copy of the Pawn when respawning) while the PlayerController instance remains the same throughout the duration of the level. This is important as there may also be moments where the PlayerController does not possess any pawn at all. This means things like opening of menus should be added to the PlayerController and not the Pawn class.

In multiplayer games the PlayerController only exists on the owning client and the server. This means in a game of 4 players, the server has 4 player controllers, and each client only has 1. This is very important in understanding where to put certain variables as when all players require a player’s variable to be replicated it should never exist in the PlayerController but in the Pawn or even PlayerState (covered later) instead.

header file declaration

  • PlayerController.h
/**
 * PlayerControllers are used by human players to control Pawns.
 *
 * ControlRotation (accessed via GetControlRotation()), determines the aiming
 * orientation of the controlled Pawn.
 *
 * In networked games, PlayerControllers exist on the server for every player-controlled pawn,
 * and also on the controlling client's machine. They do NOT exist on a client's
 * machine for pawns controlled by remote players elsewhere on the network.
 *
 * @see https://docs.unrealengine.com/latest/INT/Gameplay/Framework/Controller/PlayerController/
 */

PlayerController类:这个类的实例可以占有pawn。玩家通过它操控游戏中的实体行动。网络编程时要注意客户端和服务端上的差别。比如,若有4个客户端,则服务端上有4个PlayerController实例,客户端上只有各自的1个实例。

This class contains a PlayerCameraManager which handles view targets and camera transforms including camera shakes. Another important class the PlayerController handles is HUD (covered below) which is used for Canvas rendering (not used as much now that UMG is available) and can be great for managing some data you want to pass on to your UMG interface.

Whenever a new players joins the GameMode, a new PlayerController is created for this player via Login() in the GameModeBase class.

注意该类中有PlayerCameraManager,它负责视窗目标,相机变换,相机抖动等。
该类还负责HUD的渲染,现在,在大多场景已经渐渐被UMG取代,但是在这里调用UMG接口还是很不错的。

访问


  • GetWorld()->GetPlayerControllerIterator() // GetWorld is available in any Actor instance
  • PlayerState->GetOwner() // owner of playerstate is of type PlayerController, you will need to cast it to PlayerController yourself.
  • Pawn->GetController() // Only set when the pawn is currently ‘possessed’ (ie. controlled) by a PlayerController.

PlayerController类中的功能


大致列举头文件中的说明:

  • Camera/view related variables : 相机、视窗的相关变量,注意查看PlayerCameraManager类
  • 玩家输入事件
  • 网路连接,同步,带宽限制
  • 鼠标控制,样式、位置及坐标变换,点击射线的碰撞等等
  • 暂停、重启、结束游戏
  • 网络语音聊天
  • 播放声音、动画
  • ForceFeedback :力量反馈
  • Seamless Travel:无缝旅行
  • 在玩家模式和监视者模式间切换:如CS
  • 等等

官方案例


Unreal Match 3

UMatch3PlayerController 类
主要功能为:

相关文章

网友评论

      本文标题:虚幻 Unreal Engine 4 Gameplay Fram

      本文链接:https://www.haomeiwen.com/subject/edoslqtx.html