Selection

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務

選擇服務控制在 Roblox Studio 中選擇的 Instances

此服務在開發 Plugins 時特別有用,因為它讓開發人員可以存取和操作當前選擇。

目前選擇的 Instances 可以使用 Selection:Get()Selection:Set() 函數獲得和設置。Selection.SelectionChanged會在當前選擇變更時發生。

有關使用 SelectionPlugins 的更多信息,請參閱 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
    外掛程式安全性

    在 Roblox Studio 中返回目前選擇的 Instances 數組。

  • Remove(instancesToRemove : Instances):()
    外掛程式安全性
  • Set(selection : Instances):()
    外掛程式安全性

    將 Roblox Studio 中目前選擇的對象設為 Instances 在指定的陣列表中。

屬性

SelectionThickness

唯讀
未複製
平行讀取

方法

Add

()
外掛程式安全性

參數

instancesToAdd: Instances
預設值:""

返回

()

Get

Instances
外掛程式安全性

返回

Instances

範例程式碼

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

()
外掛程式安全性

參數

instancesToRemove: Instances
預設值:""

返回

()

Set

()
外掛程式安全性

參數

selection: Instances
預設值:""

返回

()

範例程式碼

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


範例程式碼

Selection.SelectionChanged

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