其他分享
首页 > 其他分享> > Unreal NetMode&NetRole 解析 _

Unreal NetMode&NetRole 解析 _

作者:互联网

问题

EPlayNetMode

UENUM()
enum EPlayNetMode
{
	/** A non-networked game will be started. This can be used in combination with bLaunchSeparateServer to test menu -> server flow in your game. */
	PIE_Standalone UMETA(DisplayName="Play Offline"),
	/** The editor will act as both a Server and a Client. Additional instances may be opened beyond that depending on the number of clients. */
	PIE_ListenServer UMETA(DisplayName="Play As Listen Server"),
	/** The editor will act as a Client. A server will be started for you behind the scenes to connect to. */
	PIE_Client UMETA(DisplayName="Play As Client"),
};

综上:就是方便为了给UE 编辑器用户开发测试使用。

ENetMode


 //* The network mode the game is currently running.*/
enum ENetMode
{
	/** Standalone: a game without networking, with one or more local players. Still considered a server because it has all server functionality. */
	NM_Standalone,

	/** Dedicated server: server with no local players. */
	NM_DedicatedServer,

	/** Listen server: a server that also has a local player who is hosting the game, available to other players on the network. */
	NM_ListenServer,

	/**
	 * Network client: client connected to a remote server.
	 * Note that every mode less than this value is a kind of server, so checking NetMode < NM_Client is always some variety of server.
	 */
	NM_Client,
};

ENetRole

class ENGINE_API AActor : public UObject
{
	/** Describes how much control the local machine has over the actor. */
	UPROPERTY(Replicated)
	TEnumAsByte<enum ENetRole> Role;

	/** Returns how much control the remote machine has over this actor. */
	UPROPERTY(Replicated, Transient)
	TEnumAsByte<enum ENetRole> RemoteRole;	
}

/** The network role of an actor on a local/remote network context */
enum ENetRole
{
	/** No role at all. */
	ROLE_None,
	/** Locally simulated proxy of this actor. */
	ROLE_SimulatedProxy,
	/** Locally autonomous proxy of this actor. */
	ROLE_AutonomousProxy,
	/** Authoritative control over the actor. */
	ROLE_Authority,
};

前面的ENetMode针对的是世界才能调用的,这个ENetRole是Actor才能调用的。你需要了解Actor是作为UE 可以同步的最小单元。
主要是Actor的Role和RemoteRole,大概描述的是这个Actor本地的控制性和远端的控制性。还有一点需要申明,只能是服务器复制Actor到客户端,客户端不会复制Actor到服务器。

服务器创建Actor

  • 不复制到客户端
  • Role:ROLE_Authority
  • RemoteRole:ROLE_None
  • 复制到客户端
  • Role:ROLE_Authority
  • RemoteRole:ROLE_SimulatedProxy 或 ROLE_AutonomousProxy

客户端创建Actor

  • Role:ROLE_Authority
  • RemoteRole:ROLE_None

应用:
从服务器复制一个Actor到ABCD四个客户端,那么我可以在这个Actor 的BeginPlay里判断打印log。

标签:网站,系统,解析,美元,DNS,模板,服务器,配置
来源: