signed

QiShunwang

“诚信为本、客户至上”

UE4 steam id 生成 uniqueNetid

2021/3/21 0:59:58   来源:

gameInstance.h

USTRUCT(BlueprintType)
struct FBPUniqueNetId
{
	GENERATED_BODY();
	TSharedPtr < const FUniqueNetId > UniqueNetId;
};


gameInstance.cpp

FBPUniqueNetId  UMyGameInstance::GenerateUniqueID(const FString& Str)
{
	TSharedPtr < const FUniqueNetId > netID;

	if (IOnlineSubsystem* SubSystem = IOnlineSubsystem::Get())
	{
		IOnlineIdentityPtr IdentityInterface = SubSystem->GetIdentityInterface();
		if (IdentityInterface.IsValid())
		{
			netID = IdentityInterface->CreateUniquePlayerId(Str);
		}
	}
	FBPUniqueNetId bpNetId;
	bpNetId.UniqueNetId = netID;
	return bpNetId;


}

xxx.cpp //其他地方碰到CSteamID的时候

	UMyGameInstance* gameInstance = Cast<UMyGameInstance>(GetWorld()->GetGameInstance());
			FString steamIdString = FString::FromInt(friendSteamId.ConvertToUint64());
			FBPUniqueNetId bpNetId = gameInstance->GenerateUniqueID(steamIdString);
			OnInvite.Broadcast(bpNetId);