SocialService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務
未複製

社交服務 可以幫助在 Roblox 平台上建立的關係影響社交功能。其主要用途是向玩家顯示邀請提示和電話簿,讓他們通過PromptGameInvite()PromptPhoneBook()分別向朋友發送邀請請求。當這些請求被提出時,您可以利用信號。

概要

方法

活動

回調

屬性

方法

GetPlayersByPartyId

Instances

參數

partyId: string
預設值:""

返回

Instances

HideSelfView

()

隱藏呼叫玩家的自我檢視。如果這個方法在自我視圖已隱藏時被呼叫,它不會做任何事情。


返回

()

PromptGameInvite

()

PromptGameInvite() 顯示向本地玩家發出邀請提示,通過該提示他們可以邀請朋友參加目前的體驗。在呼叫此方法之前,您應該使用 CanSendGameInviteAsync() 來確定玩家是否可以發送邀請,因為此能力可能會根據平台或玩家而異。

請參閱玩家邀請提示了解更多關於實現邀請提示、自定義提示和通知以及使用發射數據的詳情。

參數

player: Instance

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

暫停

如果指定的 Player 可以向朋好友發送呼叫邀請,返回 true 。你應該總是在呼叫 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

可選擇的 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

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() 返回的服務器存取代碼的表,分別為值。

範例程式碼

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