PluginToolbarButton
A PluginToolbarButton is an object created by the PluginToolbar:CreateButton() function. It allows the user to initiate a single, one-off action in Roblox Studio through the Click event.
When pressed, the Click event fires. A button will also remain in the pressed state, which may be set manually using SetActive. Upon plugin activation (Plugin:Activate()), buttons in all other PluginToolbars will be toggled off. If all buttons in a toolbar are off, the toolbar's plugin is deactivated (Plugin:Deactivate()).
When the game viewport is not visible, buttons will be disabled as if their Enabled property were false. Disabled buttons are desaturated and do not respond to user clicks. By setting ClickableWhenViewportHidden to true, you can allow plugin buttons to remain clickable (such as during script editing).
概要
プロパティ
Determines whether the button can be clicked when the game viewport is hidden, such as while editing a script in a different Studio tab.
Determines whether the button is clickable in general.
Determines what icon should represent the button.
方法
Sets the state of the plugin button.
イベント
Fires when the user presses and releases their cursor on the button.
プロパティ
ClickableWhenViewportHidden
ClickableWhenViewportHidden determines whether a PluginToolbarButton may be clicked while the game viewport is hidden, such as when a Script is being edited in another tab.
Typically, this property is good to enable if an action triggered by a plugin button's Click event doesn't occur in the game world (Workspace). For example, a button that opens a widget should have this property be true, as showing a widget is visible to the user even if the game view isn't visible.
Enabled
Enabled determines whether a button is clickable in general. When this property is false, the button will be greyed out and unclickable, preventing the user from firing the Click event. Buttons are enabled by default.
When re-enabling this property, the plugin button's state won't be remembered from the previous state in which the user left the button in. Instead, it will default to the last state set by SetActive() or to the inactive state if SetActive() was never used.
Plugins should disable their buttons when the button action isn't relevant in the current context. For example, a plugin button that assigns random colors to selected should not be enabled when the selection contains no parts. See the code samples for more information.
See also:
- ClickableWhenViewportHidden, which determines whether a button is clickable when the game view is hidden (and not just in general)
コードサンプル
assert(plugin, "This script must be run as a plugin")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Parts")
local pluginToolbarButton = toolbar:CreateButton(
"Randomize Colors",
"Click this button to assign random colors to selected parts",
"rbxassetid://5325741572" -- A rainbow
)
local function onClick()
local selection = Selection:Get()
for _, object in pairs(selection) do
if object:IsA("BasePart") then
object.BrickColor = BrickColor.random()
end
end
end
pluginToolbarButton.Click:Connect(onClick)
local function doesSelectionContainAPart()
local selection = Selection:Get()
for _, object in pairs(selection) do
if object:IsA("BasePart") then
return true
end
end
return false
end
local function onSelectionChanged()
pluginToolbarButton.Enabled = doesSelectionContainAPart()
end
Selection.SelectionChanged:Connect(onSelectionChanged)
onSelectionChanged()
Icon
Icon determines what icon should be shown for the button in the plugin toolbar. When this property is not set, the button will instead use the button's text given by PluginToolbar:CreateButton().
方法
イベント
Click
Click fires when the PluginToolbarButton is pressed and released by the user.
Clicking a PluginToolbarButton causes the state of the button to toggle. Call SetActive to manually set the state of the button.
コードサンプル
assert(plugin, "This script must be run as a plugin")
local toolbar = plugin:CreateToolbar("Hello World Plugin Toolbar")
local pluginToolbarButton = toolbar:CreateButton(
"Print Hello World",
"Click this button to print Hello World!",
"rbxassetid://133293265"
)
local function onClick()
print("Hello, world")
end
pluginToolbarButton.Click:Connect(onClick)