SocialService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务
未复制

SocialService facilitates social functions that impact relationships made on the Roblox platform. 它的主要用途是显示 邀请提示 和手机书给玩家,允许他们向朋友通过 PromptGameInvite() 和 0> Class.Social

概要

方法

活动

回调

属性

方法

HideSelfView

void

隐藏调用玩家的自查看。如果此方法在自视图已隐藏时调用,它将无视。


返回

void

PromptGameInvite

void

PromptGameInvite() 显示一个邀请提示,通过此邀请提示本地玩家邀请他们的朋友加入当前体验。在调用此方法之前,您应该使用 CanSendGameInviteAsync() 来确定玩家是否可以发送邀请,因为这个能

有关邀请提示的实现,请参阅Player Invite Prompts

参数

player: Instance

Class.Player 以弹出邀请提示。

experienceInviteOptions: Instance

可选的 ExperienceInviteOptions 对象用于自定义提示。

默认值:"nil"

返回

void

代码示例

The following code sample uses CanSendGameInviteAsync() to confirm whether the local Player can send an invite. If true, it then prompts the invite using PromptGameInvite().

Sending an Invite

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendGameInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canInvite = canSendGameInvite(player)
if canInvite then
SocialService:PromptGameInvite(player)
end

PromptPhoneBook

void

提示给 Player 使用手机。如果玩家选择向某人致电, CallInviteStateChanged 事件触发。您应该在使用 Class.SocialService:CanSendCallInviteAsync()|CanSendCall

如果玩家无法打开手机书,将显示错误对话框。

有关此方法的示例实现,请参阅Roblox Connect

参数

player: Instance

提示玩家使用手机书。

tag: string

字符串帮助您区分不同的电话书“入口点”或类似。例如,您可以通过定义调用玩家角色当前位于哪个区域的体验的字符串来帮助区分。


返回

void

代码示例

The following code sample, placed within a child LocalScript of a GuiButton, uses CanSendCallInviteAsync() to confirm that the player can make a call. If so, it connects PromptPhoneBook() to the button's Activated event.

SocialService:PromptPhoneBook()

local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Function to check whether the player can send a call invite
local function canSendCallingInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendCallInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canCall = canSendCallingInvite(player)
if canCall then
button.Visible = true
button.Activated:Connect(function()
SocialService:PromptPhoneBook(player, "")
end)
end

ShowSelfView

void

显示调用玩家的自查看。如果此方法在自视图已可见时调用,它将无视。

参数

selfViewPosition: Enum.SelfViewPosition

自视图的位置。

默认值:"LastPosition"

返回

void

CanSendCallInviteAsync

暂停

返回 true 如果给定的 Player 可以发送通话邀请给朋好友。您总是应该使用此方法的结果,在调用 PromptPhoneBook() 之前,因为能够打开手机书的能力可能会因玩家而变得不同。

有关此方法的示例实现,请参阅Roblox Connect

参数

player: Instance

玩家的 Player 实例可能会发送通话邀请。


返回

是否允许指定的玩家发送通话邀请。

代码示例

The following code sample, placed within a child LocalScript of a GuiButton, uses CanSendCallInviteAsync() to confirm that the player can make a call. If so, it connects PromptPhoneBook() to the button's Activated event.

SocialService:PromptPhoneBook()

local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Function to check whether the player can send a call invite
local function canSendCallingInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendCallInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canCall = canSendCallingInvite(player)
if canCall then
button.Visible = true
button.Activated:Connect(function()
SocialService:PromptPhoneBook(player, "")
end)
end

CanSendGameInviteAsync

暂停

CanSendGameInviteAsync() 返回 true 如果给定的 Player 可以邀请其他玩家到当前体验。您总是应该使用此方法的结果,前提是平台或玩家可能会变得不同。

有关玩家邀请提示的更多信息,请参阅玩家邀请提示

参数

player: Instance

玩家的 Player 实例可能会发送邀请。

recipientId: number

可选 Player.UserId 的潜在 接收者 ,用于检查发件人是否可以邀请该特定接收收件人。

默认值:0

返回

是否允许指定的玩家发送邀请。

代码示例

The following code sample uses CanSendGameInviteAsync() to confirm whether the local Player can send an invite. If true, it then prompts the invite using PromptGameInvite().

Sending an Invite

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendGameInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canInvite = canSendGameInvite(player)
if canInvite then
SocialService:PromptGameInvite(player)
end

活动

CallInviteStateChanged

该事件触发时玩家的邀请状态改变。

参数

player: Instance

玩家 Player 实例,其状态已变更为“待接待”。

inviteState: Enum.InviteState

新的调用邀请状态。


代码示例

SocialService.CallInviteStateChanged

local SocialService = game:GetService("SocialService")
local button = script.Parent
local isPhonebookOpen = false
SocialService.CallInviteStateChanged:Connect(function(_, inviteState)
local isCalling = inviteState == Enum.InviteState.Placed
if isCalling or isPhonebookOpen then
button.Visible = false
else
button.Visible = true
end
end)

GameInvitePromptClosed

当玩家关闭邀请提示时,此事件触发。

参数

player: Instance

玩家关闭提示的 Player 实例。

recipientIds: Array

不再拥有;一个空的阵数组。


PhoneBookPromptClosed

当玩家关闭电话书提示时,触发。

参数

player: Instance

玩家关闭手机书的实例 Player


回调

OnCallInviteInvoked

当从电话书放置一个调用时,调用处理器。 tag 参数可以用来区分不同的“入口点”或类似的“入口点”,如在 PromptPhoneBook() 中描述。 只有一个调用可以设置。

参数

tag: string

用于区分不同的电话书入口点之间的字符串。

callParticipantIds: Array

包含所有参与该调用的玩家的阵列。 调用者总是会是数组列中的第一个玩家。


返回

包含 PlaceIdReservedServerAccessCode 钥匙,其值为 DataModel.PlaceId 和返回 2> Class.TeleportService:ReserveServer()2> 的服务器访问代码, respectivamente.

代码示例

SocialService.OnCallInviteInvoked

local SocialService = game:GetService("SocialService")
local TeleportService = game:GetService("TeleportService")
SocialService.OnCallInviteInvoked = function()
local placeId = 0123456789 -- This is the place ID of the desired place to drop call participants into
local accessCode = TeleportService:ReserveServer(placeId)
return { ReservedServerAccessCode = accessCode, PlaceId = placeId }
end