社交服务 可以简化 Roblox 平台上影响关系的社交功能。其主要用途是向玩家显示邀请提示和电话簿,允许他们通过PromptGameInvite()和PromptPhoneBook()分别向他们的朋友发送邀请请求。当这些请求发出时,您可以利用信号。
概要
方法
活动
当玩家的呼叫状态发生变化时,发出火焰。
当玩家关闭邀请提示时发生火灾。
当玩家关闭电话手册提示时发生火灾。
回调
当从电话列表中拨打电话时的回调。
属性
方法
HideSelfView
隐藏调用玩家的自我查看。如果此方法在自我视图已隐藏时调用,则不做任何操作。
返回
PromptGameInvite
PromptGameInvite() 向本地玩家显示一个邀请提示,通过该提示他们可以邀请朋友加入当前体验。在调用此方法之前,您应该使用 CanSendGameInviteAsync() 来确定玩家是否可以发送邀请,因为此能力可能会根据平台或玩家而异。
请参阅玩家邀请提示了解更多关于实现邀请提示、自定义提示和通知以及使用发射数据的详细信息。
参数
可选 ExperienceInviteOptions 对象用于自定义提示。
返回
代码示例
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().
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以获取此方法的示例实现。
参数
用于提示手机书的玩家。
用于区分各种电话书“入口点”或类似内容的字符串。例如,您可以传递一个字符串,定义调用玩家角色当前所在的体验区域。
返回
代码示例
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.
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
显示调用玩家的自我查看。如果此方法在自我视图已可见时调用,则不做任何操作。
参数
放置自我视图的位置。
返回
CanSendCallInviteAsync
返回 true 如果给定的 Player 可以向朋好友发送通话邀请。你总是应该在调用 PromptPhoneBook() 之前使用此方法的结果,因为打开电话手册的能力可能会根据玩家而异。
请参阅Roblox Connect以获取此方法的示例实现。
参数
返回
是否指定的玩家可以发送呼叫邀请。
代码示例
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.
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() 之前使用此方法的结果,因为邀请玩家的能力可能会根据平台或玩家而异。
请参阅玩家邀请提示获取更多关于实现玩家邀请提示、自定义提示和通知以及使用发射数据的详细信息。
参数
返回
指定的玩家是否可以发送邀请。
代码示例
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().
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
当玩家的呼叫邀请状态发生变化时,此事件发生。
参数
新的呼叫邀请状态。
代码示例
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
当玩家关闭邀请提示时,此事件发生。
参数
回调
OnCallInviteInvoked
在电话书中放置调用时的回调,用于处理调用。tag 参数可以用于区分不同的“入口点”或类似的内容,如在 PromptPhoneBook() 中所述。只能设置一个回调。
参数
返回
包括 PlaceId 和 ReservedServerAccessCode 键的表,其值分别为 DataModel.PlaceId 和服务器访问代码由 TeleportService:ReserveServer() 返回, respective。
代码示例
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