Selection

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
サービス

選択サービスは、Roblox Studio で選択された Instances を制御します。

このサービスは、Plugins を開発するときに特に役立ちます。開発者が現在の選択にアクセスして操作できるようにするためです。

現在選択されている Instances は、Selection:Get() および Selection:Set() 機能を使用して取得し、設定できます。Selection.SelectionChanged イベントは、現在の選択が変更されるたびに発動します。

For more information on using SelectionPlugins , see 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
プラグインのセキュリティ

Roblox Studio で現在選択されている Instances のアレイを返します。

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

Roblox Studio で選択した Instances が変更されたときに発火します。

このイベントは新しい選択を提供しません。開発者は、現在の選択を取得するために 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)