虚幻 Unreal Engine 4 Gameplay Fram

2018-12-28  本文已影响0人  珏_Gray

参考阅读: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

/**
 * 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接口还是很不错的。

访问


PlayerController类中的功能


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

官方案例


Unreal Match 3

UMatch3PlayerController 类
主要功能为:

上一篇 下一篇

猜你喜欢

热点阅读