网络角色:
/** Locally simulated proxy of this actor. */
ROLE_SimulatedProxy,
/** Locally autonomous proxy of this actor. */
ROLE_AutonomousProxy,
/** Authoritative control over the actor. */
ROLE_Authority,
模拟代理、自主代理、权威。
在哪端 | GetLocalRole() | GetRemoteRole() | 类型 |
---|---|---|---|
服务器上 | ROLE_Authority | ROLE_AutonomousProxy | 可自控的客户端 |
服务器上 | ROLE_Authority | ROLE_SimulatedProxy | 其他客户端的模拟 |
客户端上 | ROLE_AutonomousProxy | ROLE_Authority | 用户自己 |
客户端上 | ROLE_SimulatedProxy | ROLE_Authority | 其他客户端的模拟 |
无 | ROLE_AutonomousProxy | ROLE_SimulatedProxy | 无 |
无 | ROLE_SimulatedProxy | ROLE_AutonomousProxy | 无 |
IsLocallyControlled
判断是否为本地控制
bool AController::IsLocalController() const
{
const ENetMode NetMode = GetNetMode();
if (NetMode == NM_Standalone)
{
// Not networked.
return true;
}
if (NetMode == NM_Client && GetLocalRole() == ROLE_AutonomousProxy)
{
// Networked client in control.
return true;
}
if (GetRemoteRole() != ROLE_AutonomousProxy && GetLocalRole() == ROLE_Authority)
{
// Local authority in control.
return true;
}
return false;
}
单机、客户端但是自己控制、服务端但远程不是自主控制(也就是服务端自己控制)
HasAuthority是否权威
FORCEINLINE_DEBUGGABLE bool AActor::HasAuthority() const
{
return (GetLocalRole() == ROLE_Authority);
}
只判断本地的角色
评论