SocialService

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

SocialService เพิ่มคุณสมบัติทางสังคมที่ส่งผลกระทบต่อความสัมพันธ์ที่สร้างขึ้นบนแพลตฟอร์ม Roblox ให้กับผู้ใช้ การใ

สรุป

วิธีการ

อีเวนต์

Callbacks

คุณสมบัติ

วิธีการ

HideSelfView

void

ซ่อนมุมมองของตัวผู้เล่นที่เรียกตัวเอง หากวิธีนี้ถูกเรียกในขณะที่มุมมองของตัวเองได้ถูกซ่อนไว้แล้ว มันจะไม่ทำอะไร


ส่งค่ากลับ

void

PromptGameInvite

void

PromptGameInvite() แสดงคำเชิญผ่านทางเดินทางของผู้เล่นให้กับผู้เล่นคนอื่นผ่านทางการเชิญที่พวกเขาสามารถเชิญเพื่อนของพว

ดู การเชิญผู้เล่นเพื่อสร้างการแข่งขัน สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับการใช้การเชิญผู้เล่นเพื่อสร้างการแข่งขันการปรับแต่งการแจ้งเตือน และการใช้ข้อมูลปล่อย

พารามิเตอร์

player: Instance

The Player ป็อปอัพ

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 ด้วยหนังสือโทรศัพท์ หากผู้เล่นเลือกที่จะโทรหาใครบางคน, เหตุการณ์ Class

หากผู้เล่นไม่มีสิทธิ์เปิดหนังสือโทรศัพท์ ก็จะปรากฏข้อความข้างล่าง

ดู 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

ตําแหน่งที่จะวาง self view

ค่าเริ่มต้น: "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 สามารถเชิญผู้เล่นคนอื่นไปยังประสบการณ์ปัจจุ

ดู การเชิญผู้เล่นเพิ่มเติม สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับการใช้การเชิญผู้เล่น การปรับแต่งการเชิญ และการใช้ข้อมูลปล่อย

พารามิเตอร์

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

Class.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 ของผู้เล่นที่ปิดหนังสือโทรศัพท์


Callbacks

OnCallInviteInvoked

คันธนูที่ใช้เมื่อโทรศัพท์ถูกโทรจากหนังสือโทรศัพท์ พารามิเตอร์ tag สามารถใช้เพื่อแยกระหว่าง "เขตเข้า" หรือคล้ายกันที่แตกต่างกันได้ ตามที่อธิบายไว้ใน Class

พารามิเตอร์

tag: string

ตัวอักษรเพื่อช่วยให้แยกตัวระหว่างต่างจุดเข้าถึงหนังสือโทรศัพท์ที่แตกต่างกัน

callParticipantIds: Array

รายการที่มีผู้เล่นทั้งหมดในการโทร ผู้โทรจะเป็นผู้เล่นแรกในรายการเสมอ


ส่งค่ากลับ

ตารางรวมถึงส่วน PlaceId และ ReservedServerAccessCode ที่มีค่าเป็น DataModel.PlaceId และรหัสเซิร์ฟเวอร์อุปกรณ์การเข้าถึงที่กลับมาโดย 1> Class.TeleportService:ReserveServer()1> และส่วน

ตัวอย่างโค้ด

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