Selection

Hiển Thị Bản Đã Lỗi Thời

*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.

Không Thể Tạo
Dịch Vụ

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()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 SelectionPlugins , 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.

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

Tóm Tắt

Phương Pháp

  • Add(instancesToAdd : Instances):()
    Bảo Mật Plugin
  • Get():Instances
    Bảo Mật Plugin

    Trả về một array của hiện được chọn Instances trong Roblox Studio.

  • Remove(instancesToRemove : Instances):()
    Bảo Mật Plugin
  • Set(selection : Instances):()
    Bảo Mật Plugin

    Đặt các đối tượng được chọn hiện tại trong Roblox Studio thành Instances trong mảng được cho.

Thuộc Tính

SelectionThickness

Chỉ Đọc
Không Sao Chép
Đọc Song Song

Phương Pháp

Add

()
Bảo Mật Plugin

Tham Số

instancesToAdd: Instances
Giá Trị Mặc Định: ""

Lợi Nhuận

()

Get

Instances
Bảo Mật Plugin

Lợi Nhuận

Instances

Mẫu mã

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
Selection.SelectionChanged

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

Remove

()
Bảo Mật Plugin

Tham Số

instancesToRemove: Instances
Giá Trị Mặc Định: ""

Lợi Nhuận

()

Set

()
Bảo Mật Plugin

Tham Số

selection: Instances
Giá Trị Mặc Định: ""

Lợi Nhuận

()

Mẫu mã

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)

Sự Kiện

SelectionChanged


Mẫu mã

Selection.SelectionChanged

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