Selection

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Non costruibile
Assistenza

Il servizio di selezione controlla il Instances che viene selezionato in Roblox Studio.

Questo servizio è particolarmente utile quando si sviluppa Plugins , poiché consente al programmatore di accedere e manipolare la selezione attuale.

Attualmente selezionato Instances può essere ottenuto e impostato utilizzando le funzioni Selection:Get() e Selection:Set().L'evento Selection.SelectionChanged si attiva ogni volta che viene modificata la selezione attuale.

Per ulteriori informazioni sull'uso di Selection e Plugins , vedi Plugin .

La selezione viene spesso utilizzata anche nella barra dei comandi, per impostare proprietà nascoste o eseguire funzioni per la selezione Instances .

Si noti che questa classe si applica solo a Roblox Studio e non ha applicabilità ai giochi.

Campioni di codice

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

Sommario

Metodi

  • Add(instancesToAdd : Instances):()
    Sicurezza Plugin
  • Get():Instances
    Sicurezza Plugin

    Restituisce un array di attualmente selezionati Instances in Roblox Studio.

  • Remove(instancesToRemove : Instances):()
    Sicurezza Plugin
  • Set(selection : Instances):()
    Sicurezza Plugin

    Imposta gli oggetti selezionati attualmente in Roblox Studio a Instances nell'vettorefornito.

Proprietà

SelectionThickness

Sola Lettura
Non Replicato
Lettura Parallela

Metodi

Add

()
Sicurezza Plugin

Parametri

instancesToAdd: Instances
Valore predefinito: ""

Restituzioni

()

Get

Instances
Sicurezza Plugin

Restituisce un array di attualmente selezionati Instances in Roblox Studio.

Se non vengono selezionati Instances , l'array restituito sarà vuoto.Questa funzione può essere utilizzata in combinazione con l'evento Selection.SelectionChanged per ottenere la selezione ogni volta che cambia.

Nota, questa funzione può essere utilizzata solo in Plugins o nella riga di comando.

Per cambiare la selezione attuale, vedi Selection:Set() .


Restituzioni

Instances

Un array di attualmente selezionati Instances .

Campioni di codice

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

()
Sicurezza Plugin

Parametri

instancesToRemove: Instances
Valore predefinito: ""

Restituzioni

()

Set

()
Sicurezza Plugin

Imposta gli oggetti selezionati attualmente in Roblox Studio a Instances nell'vettorefornito.

Chiamare questa funzione farà Lanciarel'evento Selection.SelectionChanged , a meno che il nuovo set di selezione sia identico alla selezione precedente.

Tieni presente che questa funzione sovrascrive la selezione esistente. Tuttavia, usando Selection:Get() un Instance può essere aggiunto alla selezione esistente come segue:


local selected = Selection:Get()
table.insert(selected, object)
Selection:Set(selected)

Parametri

selection: Instances

Un array di Instances per impostare la selezione attuale.

Valore predefinito: ""

Restituzioni

()

Campioni di codice

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)

Eventi

SelectionChanged

Si accende quando il Instances selezionato in Roblox Studio cambia.

Si noti che questo evento non fornisce la nuova selezione. Gli sviluppatori dovranno utilizzare la funzione Selection:Get() per ottenere la selezione attuale.

Sebbene questo evento possa essere utilizzato al di fuori dei plugin e della barra dei comandi, si applica solo alla selezione in Roblox Studio e quindi non ha funzionalità al di fuori di Studio.

Per cambiare la selezione utilizza la funzione Selection:Set().


Campioni di codice

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)