Selection
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Dịch vụ lựa chọn kiểm soát Instances được chọn trong Roblox Studio.
Dịch vụ này rất hữu ích khi phát triển Plugins , vì nó cho phép nhà phát triển truy cập và thao tác với lựa chọn hiện tại.
Hiện đã chọn Instances có thể được lấy và đặt bằng cách sử dụng các chức năng Selection:Get() và Selection:Set().Sự kiện Selection.SelectionChanged xảy ra khi nào thay đổi lựa chọn hiện tại.
Để biết thêm thông tin về việc sử dụng Selection và Plugins , hãy xem Plugin .
Lựa chọn cũng thường được sử dụng trong thanh lệnh, để đặt các thuộc tính ẩn hoặc chạy chức năng cho đối tượng được chọn Instances .
Lưu ý lớp này chỉ áp dụng cho Roblox Studio và không có tính ứng dụng cho trò chơi.
Mẫu mã
The following code sample, when used in a plugin or the command bar, will rotate currently selected BaseParts.
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
Tóm Tắt
Thuộc Tính
Phương Pháp
Sự Kiện
Bắt lửa khi Instances được chọn trong các thay đổi của Roblox Studio.
Thuộc Tính
SelectionThickness
Phương Pháp
Add
Tham Số
Lợi Nhuận
Get
Lợi Nhuận
Mẫu mã
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
local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("Selection contains " .. #selection:Get() .. " items.")
end)
Remove
Tham Số
Lợi Nhuận
Set
Tham Số
Lợi Nhuận
Mẫu mã
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)
Sự Kiện
SelectionChanged
Mẫu mã
local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("Selection contains " .. #selection:Get() .. " items.")
end)