SocialService

显示已弃用

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

无法创建
服务
未复制

社交服务 可以简化 Roblox 平台上影响关系的社交功能。其主要用途是向玩家显示邀请提示和电话簿,允许他们通过PromptGameInvite()PromptPhoneBook()分别向他们的朋友发送邀请请求。当这些请求发出时,您可以利用信号。

概要

方法

活动

回调

属性

方法

GetPlayersByPartyId

Instances

参数

partyId: string
默认值:""

返回

Instances

HideSelfView

()

隐藏调用玩家的自我查看。如果此方法在自我视图已隐藏时调用,则不做任何操作。


返回

()

PromptGameInvite

()

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

请参阅玩家邀请提示了解更多关于实现邀请提示、自定义提示和通知以及使用发射数据的详细信息。

参数

player: Instance

The Player 以提示与邀请弹出窗口。

默认值:""
experienceInviteOptions: Instance

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

默认值:"nil"

返回

()

代码示例

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

()

向给定的 Player 提示使用电话簿。如果玩家选择呼叫某人,那么 CallInviteStateChanged 事件将触发。你应该在调用 PromptPhoneBook() 之前使用 CanSendCallInviteAsync() ,因为能够查看电话列表的能力可能会根据玩家而异。

如果玩家不符合打开电话列表的条件,将显示错误对话框。

请参阅Roblox Connect以获取此方法的示例实现。

参数

player: Instance

用于提示手机书的玩家。

默认值:""
tag: string

用于区分各种电话书“入口点”或类似内容的字符串。例如,您可以传递一个字符串,定义调用玩家角色当前所在的体验区域。

默认值:""

返回

()

代码示例

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

()

显示调用玩家的自我查看。如果此方法在自我视图已可见时调用,则不做任何操作。

参数

selfViewPosition: Enum.SelfViewPosition

放置自我视图的位置。

默认值:"LastPosition"

返回

()

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 可以邀请其他玩家进入当前体验。你总是应该在调用 PromptGameInvite() 之前使用此方法的结果,因为邀请玩家的能力可能会根据平台或玩家而异。

请参阅玩家邀请提示获取更多关于实现玩家邀请提示、自定义提示和通知以及使用发射数据的详细信息。

参数

player: Instance

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

默认值:""
recipientId: number

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

默认值: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

GetPartyAsync

暂停

参数

partyId: string
默认值:""

返回

活动

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 和服务器访问代码由 TeleportService:ReserveServer() 返回, respective。

代码示例

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