SocialService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
บริการโซเชียล ช่วยให้การทำงานทางสังคมที่มีผลกระทบต่อความสัมพันธ์ที่ทำบนแพลตฟอร์ม Robloxการใช้งานหลักคือการแสดง แจ้งเตือนการเชิญ และสมุดโทรศัพท์ให้กับผู้เล่นเพื่อให้พวกเขาสามารถส่งคำขอเชิญไปยังเพื่อนของพวกเขาผ่าน PromptGameInvite() และ PromptPhoneBook() ตามลำดับคุณสามารถใช้สัญญาณเมื่อมีคำขอดังกล่าวได้
สรุป
วิธีการ
อีเวนต์
เกิดไฟไหม้เมื่อสถานะการเรียกของผู้เล่นเปลี่ยนแปลง
เกิดไฟไหม้เมื่อผู้เล่นปิดการแจ้งเตือนการเชิญ
เกิดไฟไหม้เมื่อผู้เล่นปิดการแจ้งเตือนในสมุดโทรศัพท์
Callbacks
การโทรกลับเมื่อมีการวางสายจากสมุดโทรศัพท์
คุณสมบัติ
วิธีการ
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 จะเกิดขึ้นคุณควรใช้ CanSendCallInviteAsync() ก่อนที่จะโทร 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
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() เนื่องจากความสามารถในการเชิญผู้เล่นอาจแตกต่างกันไปขึ้นอยู่กับแพลตฟอร์มหรือผู้เล่น
ดู คําเชิญผู้เล่น สําหรับรายละเอียดเพิ่มเติมเกี่ยวกับการดําเนินการคําเชิญผู้เล่นการปรับแต่งคําเชิญและการแจ้งเตือน และการใช้ข้อมูลเปิดตัว
พารามิเตอร์
ตัวเลือก Player.UserId ของผู้รับที่อาจจะเป็นไปได้ **** ใช้เพื่อตรวจสอบว่าผู้ส่งสามารถเชิญผู้รับเฉพาะรายนั้นได้หรือไม่
ส่งค่ากลับ
ว่าผู้เล่นที่ระบุสามารถส่งคำเชิญได้หรือไม่
ตัวอย่างโค้ด
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
อีเวนต์นี้จะเกิดขึ้นเมื่อผู้เล่นปิดการแจ้งเตือนการเชิญ
พารามิเตอร์
ไม่ได้เติมแล้ว; เป็น阵列ว่างเปล่า
Callbacks
OnCallInviteInvoked
การโทรกลับเพื่อดำเนินการเมื่อมีการวางสายจากสมุดโทรศัพท์พารามิเตอร์ tag สามารถใช้เพื่อแยกแยะระหว่าง "จุดเข้า" ที่แตกต่างกันหรือคล้ายกันตามที่อธิบายไว้ใน PromptPhoneBook()สามารถตั้งค่าคอลเลกชันกลับเพียงครั้งเดียว
พารามิเตอร์
สตริงเพื่อช่วยแยกแยะระหว่างจุดเข้าสู่รายชื่อโทรศัพท์ที่แตกต่างกัน
รายการที่มีผู้เล่นทั้งหมดที่มีส่วนร่วมในการโทร ผู้โทรจะเป็นผู้เล่นแรกในรายการเสมอ
ส่งค่ากลับ
ตารางรวมถึงแป้น PlaceId และ ReservedServerAccessCode ที่มีค่าเป็น DataModel.PlaceId และรหัสการเข้าถึงเซิร์ฟเวอร์ที่ส่งคืนโดย TeleportService:ReserveServer() ตามลำดับ
ตัวอย่างโค้ด
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