Selection
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
選択サービスは、Roblox Studio で選択された Instances を制御します。
このサービスは、Plugins を開発するときに特に役立ちます。開発者が現在の選択にアクセスして操作できるようにするためです。
現在選択されている Instances は、Selection:Get() および Selection:Set() 機能を使用して取得し、設定できます。Selection.SelectionChanged イベントは、現在の選択が変更されるたびに発動します。
For more information on using Selection と Plugins , see Plugin .
選択はまた、コマンドバーでもよく使用され、隠しプロパティを設定したり、選択した Instances の機能を実行したりします。
このクラスは Roblox Studio にのみ適用され、ゲームには適用できません。
コードサンプル
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
プロパティ
SelectionThickness
方法
Add
パラメータ
戻り値
Get
Roblox Studio で現在選択されている Instances のアレイを返します。
Instances が選択されない場合、返された配列は空になります。この機能は、Selection.SelectionChanged イベントと組み合わせて使用することで、変更されるたびに選択を取得できます。
注: この機能は Plugins またはコマンドラインでのみ使用できます。
現在の選択を変更するには、Selection:Set() を参照してください。
戻り値
現在選択されている配列 Instances 。
コードサンプル
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
This example prints the number of selected items whenever SelectionChanged is fired:
local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("Selection contains " .. #selection:Get() .. " items.")
end)
Remove
パラメータ
戻り値
Set
Roblox Studio で現在選択されているオブジェクトを、指定された配列に Instances に設定します。
この関数を呼び出すと、新しい選択セットが前の選択と同じでない限り、Selection.SelectionChangedイベントが発動します。
この機能は、既存の選択を上書きしますが、Selection:Get() と Instance を使用すると、次のように既存の選択に追加できます:
local selected = Selection:Get()table.insert(selected, object)Selection:Set(selected)
パラメータ
現在の選択を設定するための Instances の配列。
戻り値
コードサンプル
This code sample will select every BasePart in the workspace that is Bright red.
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
Roblox Studio で選択した Instances が変更されたときに発火します。
このイベントは新しい選択を提供しません。開発者は、現在の選択を取得するために Selection:Get() 関数を使用する必要があります。
このイベントは、プラグインとコマンドバーの外で使用できますが、Roblox Studio での選択にのみ適用され、スタジオ外では機能しません。
選択を変更するには、Selection:Set() 関数を使用します。
コードサンプル
This example prints the number of selected items whenever SelectionChanged is fired:
local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("Selection contains " .. #selection:Get() .. " items.")
end)