Selection

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

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

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

บริการเลือกควบคุม Instances ที่เลือกใน Roblox Studio

บริการนี้มีประโยชน์เป็นพิเศษเมื่อพัฒนา Plugins เนื่องจากช่วยให้นักพัฒนาสามารถเข้าถึงและจัดการการเลือกปัจจุบันได้

ปัจจุบันเลือก Instances สามารถรับและตั้งค่าโดยใช้ฟังก์ชัน Selection:Get() และ Selection:Set()อีเวนต์ Selection.SelectionChanged จะเกิดขึ้นเมื่อมีการเปลี่ยนแปลงการเลือกปัจจุบัน

สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการใช้ Selection และ Plugins ดูที่ Plugin

การเลือกยังมักใช้ในแถบคําสั่งเพื่อตั้งค่าคุณสมบัติที่ซ่อนอยู่หรือรันฟังก์ชันสําหรับสิ่งที่เลือก Instances

โปรดทราบว่าคลาสนี้ใช้กับ Roblox Studio เท่านั้นและไม่สามารถใช้กับเกมได้

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

The following code sample, when used in a plugin or the command bar, will rotate currently selected BaseParts.

Selection

local Selection = game:GetService("Selection")
for _, object in pairs(Selection:Get()) do
if object:IsA("BasePart") then
object.CFrame = object.CFrame * CFrame.Angles(0, math.pi / 2, 0)
end
end

สรุป

คุณสมบัติ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

วิธีการ

  • Add(instancesToAdd : Instances):()
    การรักษาความปลอดภัยของปลั๊กอิน
  • Get():Instances
    การรักษาความปลอดภัยของปลั๊กอิน

    ส่งคืนคอลเลกชันของตัวเลือกที่เลือกในปัจจุบัน Instances ใน Roblox Studio

  • Remove(instancesToRemove : Instances):()
    การรักษาความปลอดภัยของปลั๊กอิน
  • Set(selection : Instances):()
    การรักษาความปลอดภัยของปลั๊กอิน

    ตั้งค่าวัตถุที่เลือกในปัจจุบันใน Roblox Studio เป็น Instances ในช่วงที่กำหนด

อีเวนต์

คุณสมบัติ

SelectionThickness

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

วิธีการ

Add

()
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

instancesToAdd: Instances
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

Get

Instances
การรักษาความปลอดภัยของปลั๊กอิน

ส่งคืนคอลเลกชันของตัวเลือกที่เลือกในปัจจุบัน Instances ใน Roblox Studio

หากไม่มี Instances ถูกเลือก ค่าตัวเลขในอาร์เรย์ที่ส่งคืนจะว่างเปล่าฟังก์ชันนี้สามารถใช้ร่วมกับอีเวนต์ Selection.SelectionChanged เพื่อรับการเลือกเมื่อมันเปลี่ยนแปลงได้

โปรดทราบว่าฟังก์ชันนี้สามารถใช้ได้เฉพาะใน Plugins หรือเส้นคำสั่งเท่านั้น

สำหรับการเปลี่ยนการเลือกปัจจุบันโปรดดู Selection:Set()


ส่งค่ากลับ

Instances

ชุดของตัวเลือกที่เลือกในปัจจุบัน Instances .

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

The following code sample, when used in a plugin or the command bar, will rotate currently selected BaseParts.

Selection

local Selection = game:GetService("Selection")
for _, object in pairs(Selection:Get()) do
if object:IsA("BasePart") then
object.CFrame = object.CFrame * CFrame.Angles(0, math.pi / 2, 0)
end
end

This example prints the number of selected items whenever SelectionChanged is fired:

Selection.SelectionChanged

local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("Selection contains " .. #selection:Get() .. " items.")
end)

Remove

()
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

instancesToRemove: Instances
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

Set

()
การรักษาความปลอดภัยของปลั๊กอิน

ตั้งค่าวัตถุที่เลือกในปัจจุบันใน Roblox Studio เป็น Instances ในช่วงที่กำหนด

การเรียกฟังก์ชันนี้จะทําให้เหตุการณ์ Selection.SelectionChanged เกิดขึ้น เว้นแต่ชุดการเลือกใหม่จะเหมือนกับชุดการเลือกก่อนหน้า

โปรดทราบว่าฟังก์ชันนี้จะเขียนทับการเลือกที่มีอยู่ อย่างไรก็ตาม การใช้ Selection:Get() และ Instance สามารถเพิ่มลงในการเลือกที่มีอยู่ได้ดังนี้:


local selected = Selection:Get()
table.insert(selected, object)
Selection:Set(selected)

พารามิเตอร์

selection: Instances

ชุดของ Instances เพื่อตั้งค่าการเลือกปัจจุบัน

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

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

This code sample will select every BasePart in the workspace that is Bright red.

Selection Set

local Selection = game:GetService("Selection")
local newSelection = {}
for _, object in pairs(workspace:GetDescendants()) do
if object:IsA("BasePart") and object.BrickColor == BrickColor.new("Bright red") then
table.insert(newSelection, object)
end
end
Selection:Set(newSelection)

อีเวนต์

SelectionChanged

เกิดไฟไหม้เมื่อ Instances ถูกเลือกใน Roblox Studio เปลี่ยนแปลง

โปรดทราบว่าอีเวนต์นี้ไม่ให้ตัวเลือกใหม่ ผู้พัฒนาจะต้องใช้ฟังก์ชัน Selection:Get() เพื่อรับตัวเลือกปัจจุบัน

แม้ว่าอีเวนต์นี้จะสามารถใช้ภายนอกปลั๊กอินและแถบคําสั่งได้ แต่มันใช้ได้เฉพาะการเลือกใน Roblox Studio และดังนั้นจึงไม่มีฟังก์ชันภายนอกสตูดิโอ

เพื่อเปลี่ยนการเลือกใช้ฟังก์ชัน Selection:Set()


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

This example prints the number of selected items whenever SelectionChanged is fired:

Selection.SelectionChanged

local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("Selection contains " .. #selection:Get() .. " items.")
end)