蓝图部分节点cpp逻辑

网络角色:

/** 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_AuthorityROLE_AutonomousProxy可自控的客户端
服务器上ROLE_AuthorityROLE_SimulatedProxy其他客户端的模拟
客户端上ROLE_AutonomousProxyROLE_Authority用户自己
客户端上ROLE_SimulatedProxyROLE_Authority其他客户端的模拟
ROLE_AutonomousProxyROLE_SimulatedProxy
ROLE_SimulatedProxyROLE_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);
}

只判断本地的角色

评论