SocialService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
SocialService เพิ่มคุณสมบัติทางสังคมที่ส่งผลกระทบต่อความสัมพันธ์ที่สร้างขึ้นบนแพลตฟอร์ม Roblox ให้กับผู้ใช้ การใ
สรุป
วิธีการ
อีเวนต์
เปิดให้บริการเมื่อสถานะการเรียกของผู้เล่นเปลี่ยนแปลง
จะเกิดขึ้นเมื่อผู้เล่นปิดการเรียกร้องเชิญ
เกิดขึ้นเมื่อผู้เล่นปิดการโปรดให้โทรศัพท์
Callbacks
การโทรกลับเมื่อโทรจากหนังสือโทรศัพท์
คุณสมบัติ
วิธีการ
HideSelfView
ซ่อนมุมมองของตัวผู้เล่นที่เรียกตัวเอง หากวิธีนี้ถูกเรียกในขณะที่มุมมองของตัวเองได้ถูกซ่อนไว้แล้ว มันจะไม่ทำอะไร
ส่งค่ากลับ
PromptGameInvite
PromptGameInvite() แสดงคำเชิญผ่านทางเดินทางของผู้เล่นให้กับผู้เล่นคนอื่นผ่านทางการเชิญที่พวกเขาสามารถเชิญเพื่อนของพว

ดู การเชิญผู้เล่นเพื่อสร้างการแข่งขัน สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับการใช้การเชิญผู้เล่นเพื่อสร้างการแข่งขันการปรับแต่งการแจ้งเตือน และการใช้ข้อมูลปล่อย
พารามิเตอร์
ตัวเลือก 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 ด้วยหนังสือโทรศัพท์ หากผู้เล่นเลือกที่จะโทรหาใครบางคน, เหตุการณ์ Class
หากผู้เล่นไม่มีสิทธิ์เปิดหนังสือโทรศัพท์ ก็จะปรากฏข้อความข้างล่าง
ดู 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
แสดงมุมมองของตัวผู้เล่นที่กำลังโทร หากวิธีนี้ถูกเรียกในขณะที่มุมมองของตัวผู้เล่นมองเห็นได้อยู่แล้ว ไม่ได้สร้างผล
พารามิเตอร์
ตําแหน่งที่จะวาง self view
ส่งค่ากลับ
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 สามารถเชิญผู้เล่นคนอื่นไปยังประสบการณ์ปัจจุ
ดู การเชิญผู้เล่นเพิ่มเติม สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับการใช้การเชิญผู้เล่น การปรับแต่งการเชิญ และการใช้ข้อมูลปล่อย
พารามิเตอร์
ตัวเลือก 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
เหตุการณ์นี้จะเกิดขึ้นเมื่อสถานะการเรียกของผู้เล่นเปลี่ยนแปลง
พารามิเตอร์
Class.Player ตัวอินสแตนซ์ของผู้เล่นที่มีสถานะเรียกเชิญ
สถานะการเรียกใหม่
ตัวอย่างโค้ด
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 สามารถใช้เพื่อแยกระหว่าง "เขตเข้า" หรือคล้ายกันที่แตกต่างกันได้ ตามที่อธิบายไว้ใน Class
พารามิเตอร์
ตัวอักษรเพื่อช่วยให้แยกตัวระหว่างต่างจุดเข้าถึงหนังสือโทรศัพท์ที่แตกต่างกัน
รายการที่มีผู้เล่นทั้งหมดในการโทร ผู้โทรจะเป็นผู้เล่นแรกในรายการเสมอ
ส่งค่ากลับ
ตารางรวมถึงส่วน PlaceId และ ReservedServerAccessCode ที่มีค่าเป็น DataModel.PlaceId และรหัสเซิร์ฟเวอร์อุปกรณ์การเข้าถึงที่กลับมาโดย 1> Class.TeleportService:ReserveServer()1> และส่วน
ตัวอย่างโค้ด
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