SocialService

顯示已棄用項目

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

無法建立
服務
未複製

SocialService 可以簡化與 Roblox 平台上的關係所造成的社交功能。它的主要用途是顯示 邀請提示 和電話書給玩家,讓他們能夠通過 Class.SocialService:PromptGameInvite()|PromptGameInv

概要

方法

活動

回調

屬性

方法

HideSelfView

void

隱藏玩家自觀的自觀檢視。如果此方法在自觀視圖已隱藏時呼叫,它沒有任何作用。


返回

void

PromptGameInvite

void

PromptGameInvite() 顯示邀請提示給本地玩家,讓他們邀請他們的朋友來當前體驗。在呼叫此方法之前,您應該使用 CanSendGameInviteAsync() 來確認玩家是否能夠發送邀請

有關邀請提示的實現、自訂提示和通知,以及使用啟動資料,請參閱玩家邀請提示

參數

player: Instance

Class.Player 以提示彈出(視窗、通知)請 popup。

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:CanSendCallInv

如果玩家無資格打開電話簿,將顯示錯誤對話框。

有關此方法的示例實現,請參閱 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 可以邀请其他玩家到当前体體驗。您应该总是使用此方法的结果,前提是您调用的 0> Class.SocialService:Prom

有關玩家邀請提示的更多內容,請參閱Player Invite Prompts

參數

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 參數可用於與不同的「入口點」或類似的區分,如在 Class.SocialService:PromptPhoneBook()|PromptPhoneBook() 中所述。只有一個回撥才能設設定。

參數

tag: string

字串來幫助不同的電話簿項目區分。

callParticipantIds: Array

包含所有參與呼叫的玩家的陣列。呼叫者將永遠是陣列中的第一個玩家。


返回

包含 PlaceIdReservedServerAccessCode 鑰匙的桌子,其值是 DataModel.PlaceId 和 2>Class.TeleportService:ReserveServer() 返回的伺服器存取代碼,分別是 5>Class.DataModel.PlaceId5> 和 8>Class.TeleportService:ReserveServer()8> 。

範例程式碼

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