Plugin

非推奨を表示
作成できません

Plugin is the main object responsible for creating basic Studio widgets, plugin toolbars, plugin buttons, and more. It is a custom add-on to Studio which adds new behavior and features that are not normally included. The Plugin object can be accessed through the plugin global reference in a Script that is executed as a plugin.

コードサンプル

Script - Pass the Plugin Global to a ModuleScript

assert(plugin, "This script must be run as a plugin!")
-- Code beyond this point will execute only if the script is run as a plugin
-- Load the module and pass the plugin reference
local pluginModule = require(script.Parent.PluginModule)
pluginModule:Initialize(plugin)
-- Verify if the plugin reference was initialized
pluginModule:CheckForPluginGlobal()
ModuleScript - Receive and Store the Plugin Global

local pluginModule = {}
local plugin -- Local plugin reference
-- Initialize the plugin reference if not already set
function pluginModule:Initialize(pluginReference: Plugin)
if plugin ~= pluginReference then
plugin = pluginReference
else
error("Plugin is already initialized")
end
end
-- Check if the plugin reference is set and print out appropriate info
function pluginModule:CheckForPluginGlobal()
if plugin ~= nil then
print("Plugin reference is set!")
else
warn("Plugin reference is missing!")
end
end
return pluginModule

概要

プロパティ

  • 読み取り専用
    複製されていません
    並列読み取り

    Returns whether the user enabled Collisions in studio under the Model tab.

  • 読み取り専用
    複製されていません
    並列読み取り

    Returns the grid snapping size the user has set in Studio.

方法

イベント

プロパティ

CollisionEnabled

読み取り専用
複製されていません
並列読み取り

Returns whether the user enabled Collisions in studio under the Model tab.

DisableUIDragDetectorDrags

並列読み取り
Robloxのスクリプトセキュリティ

GridSize

読み取り専用
複製されていません
並列読み取り

Returns the grid snapping size the user has set in Studio under the Model or Avatar tabs. Note that this property may have slight rounding errors; for example it may be 0.0099999997764826 for a user setting of 1 or 0.4000000059604645 for a user setting of 0.4.

方法

Activate

void
プラグインのセキュリティ

This function sets the state of the calling plugin to activated. Activating the plugin allows mouse control through the Plugin:GetMouse() method.

At any given time there are either 0 or 1 Activated Plugins. Activating a plugin will deactivate all other plugins (they will receive a Plugin.Deactivation event).

See also:

  • Plugin:IsActivatedWithExclusiveMouse(), returns true if this plugin is currently active with an exclusive mouse, after having been activated via this function
  • Plugin.Unloading, fires immediately before the plugin is unloaded or reloaded via uninstallation, deactivation, or updating

パラメータ

exclusiveMouse: bool

A boolean specifying whether to activate the plugin with exclusive mouse. If true, a PluginMouse can be retrieved via Plugin:GetMouse().


戻り値

void

CreatePluginAction

プラグインのセキュリティ

This function creates a PluginAction which is an object that represents a generic performable action in Roblox Studio, with no directly associated Toolbar or Enum.Button. In Roblox Studio, they can be assigned a keyboard shortcut under File → Advanced → Customize Shortcuts…, and they can also be added to the Quick Access Toolbar.

When an action is triggered, the PluginAction.Triggered event is signaled.

In order for PluginActions work as expected, they must be created using this function.

See also:

パラメータ

actionId: string

Must be a unique string that identifies this PluginAction from others.

text: string

The displayed name of the action.

statusTip: string

The displayed description of the action.

iconName: string

The name of the icon used to display the plugin.

既定値: ""
allowBinding: bool

Whether the PluginAction will be hidden from Studio's shortcuts view. Useful for contextual actions. Defaults to true.

既定値: true

戻り値

コードサンプル

Creating a PluginAction

local plugin = plugin or getfenv().PluginManager():CreatePlugin()
plugin.Name = "Plugin"
local function actionTriggered()
print("Hello world!")
end
local pluginAction = plugin:CreatePluginAction(
"HelloWorldAction",
"Hello World",
"Prints a 'Hello world!'",
"rbxasset://textures/sparkle.png",
true
)
pluginAction.Triggered:Connect(actionTriggered)

CreatePluginMenu

プラグインのセキュリティ

This function creates a new PluginMenu, which is a context menu that can be shown in Studio that displays a list of PluginActions and supports submenus.

In order for PluginMenus to work as expected, they must be created using this function.

See also:

パラメータ

id: string

Unique ID for the menu.

title: string

The text to be displayed when used as a sub menu.

既定値: ""
icon: string

The icon to be displayed when used as a sub menu.

既定値: ""

戻り値

コードサンプル

Creating a PluginMenu and PluginMenuAction

-- This code can be pasted into the command bar, but only once
local plugin = plugin or getfenv().PluginManager():CreatePlugin()
plugin.Name = "Plugin"
plugin.Parent = workspace
local pluginMenu = plugin:CreatePluginMenu(math.random(), "Test Menu")
pluginMenu.Name = "Test Menu"
pluginMenu:AddNewAction("ActionA", "A", "rbxasset://textures/loading/robloxTiltRed.png")
pluginMenu:AddNewAction("ActionB", "B", "rbxasset://textures/loading/robloxTilt.png")
local subMenu = plugin:CreatePluginMenu(math.random(), "C", "rbxasset://textures/explosion.png")
subMenu.Name = "Sub Menu"
subMenu:AddNewAction("ActionD", "D", "rbxasset://textures/whiteCircle.png")
subMenu:AddNewAction("ActionE", "E", "rbxasset://textures/icon_ROBUX.png")
pluginMenu:AddMenu(subMenu)
pluginMenu:AddSeparator()
pluginMenu:AddNewAction("ActionF", "F", "rbxasset://textures/sparkle.png")
local toggle = Instance.new("BoolValue")
toggle.Name = "TogglePluginMenu"
toggle.Parent = workspace
local function onToggled()
if toggle.Value then
toggle.Value = false
local selectedAction = pluginMenu:ShowAsync()
if selectedAction then
print("Selected Action:", selectedAction.Text, "with ActionId:", selectedAction.ActionId)
else
print("User did not select an action!")
end
end
end
toggle.Changed:Connect(onToggled)

CreateToolbar

プラグインのセキュリティ

The CreateToolbar function creates a new PluginToolbar with the given name. The toolbar can then be used to create plugin buttons.

パラメータ

name: string

The visible text on the toolbar, labeling the group of buttons contained within.


戻り値

コードサンプル

Plugin:CreateToolbar

plugin:CreateToolbar("ExampleToolbar")

Deactivate

void
プラグインのセキュリティ

Deactivates the plugin. This will disengage the associated PluginMouse if it has been activated

See also:


戻り値

void
プラグインのセキュリティ

Returns the Enum.JointCreationMode the user has set in studio under the Model tab.


戻り値

GetMouse

プラグインのセキュリティ

GetMouse returns a PluginMouse that can be used while the plugin is active through Plugin:Activate().


戻り値

コードサンプル

Plugin:GetMouse

local mouse = plugin:GetMouse()
local function button1Down()
print("Button 1 pressed from PluginMouse")
end
mouse.Button1Down:Connect(button1Down)

GetSelectedRibbonTool

プラグインのセキュリティ

GetSelectedRibbonTool return the currently selected Enum.RibbonTool. It returns an Enum that corresponds to a particular tool. This will return whether the tool is selected manually or programmatically via Plugin:SelectRibbonTool().


戻り値

コードサンプル

Plugin:GetSelectedRibbonTool

plugin:SelectRibbonTool(Enum.RibbonTool.Move, UDim2.new())
task.wait() -- wait for next frame
local selectedRibbonTool = plugin:GetSelectedRibbonTool()
print("The selected RibbonTool is", selectedRibbonTool)

GetSetting

Variant
プラグインのセキュリティ

Retrieves a previously stored value with the given key, or nil if the given key doesn't exist.

Because multiple instances of the same plugin can run simultaneously (for example, if multiple Studio windows are open), you shouldn't depend on this value staying the same over time. The other plugin instances can update the setting at any time.

This call can silently fail and return nil if multiple instances of the same plugin are actively reading and writing data. If your plugin expects to write to settings frequently, you should double-check the returned value from this call after a short while to distinguish between a setting being temporarily unavailable and a setting not existing.

パラメータ

key: string

戻り値

Variant

コードサンプル

Plugin:GetSetting

local RAN_BEFORE_KEY = "RanBefore"
local didRunBefore = plugin:GetSetting(RAN_BEFORE_KEY)
if didRunBefore then
print("Welcome back!")
else
plugin:SetSetting(RAN_BEFORE_KEY, true)
print("Welcome! Thanks for installing this plugin!")
end

Intersect

プラグインのセキュリティ

パラメータ

objects: Instances

戻り値

IsActivated

プラグインのセキュリティ

This function returns true if this plugin is currently active, after having been activated via the Plugin:Activate() function.


戻り値

A boolean indicating whether the plugin is currently active.

IsActivatedWithExclusiveMouse

プラグインのセキュリティ

This function returns true if this plugin is currently active with an exclusive mouse, after having been activated via the Plugin:Activate() function. If this returns true, a PluginMouse can be retrieved via Plugin:GetMouse().

See also:

  • Plugin.Deactivation, fires when the plugin is deactivated
  • Plugin.Unloading, fires immediately before the plugin is unloaded or reloaded via uninstallation, deactivation, or updating

戻り値

Whether this plugin is currently active with an exclusive mouse.

Negate

Instances
プラグインのセキュリティ

Negates the given parts and returns the resulting NegateOperations.

パラメータ

objects: Instances

戻り値

Instances

OpenScript

void
プラグインのセキュリティ

Used to open the given script instance in an editor window, in Roblox studio, at the given line. If no line is given as an argument it will default to 1.

パラメータ

lineNumber: number
既定値: 1

戻り値

void

コードサンプル

Plugin:OpenScript

local newScript = Instance.new("Script")
newScript.Parent = workspace
plugin:OpenScript(newScript)

OpenWikiPage

void
プラグインのセキュリティ

Opens the context help window to the wiki page that url links to.

パラメータ

url: string

戻り値

void

コードサンプル

Plugin:OpenWikiPage

plugin:OpenWikiPage("API:Class/BasePart")

SaveSelectedToRoblox

void
プラグインのセキュリティ

Opens an upload window for the user's current selection.


戻り値

void

SelectRibbonTool

void
プラグインのセキュリティ

Activates the specified Roblox Studio tool. If the tool opens a window, the position parameter specifies where it should be shown on the screen.

Note:

  • An object must be selected in order for this to work correctly.
  • Altering the scale fields of the position property will not affect the dialog popups.

パラメータ

position: UDim2

戻り値

void

Separate

Instances
プラグインのセキュリティ

Separates the given UnionOperations and returns the resulting parts.

パラメータ

objects: Instances

戻り値

Instances

SetSetting

void
プラグインのセキュリティ

Stores a given value for later use under the given key. The value will persist even after Roblox Studio is closed. These settings are saved in JSON format as a map with string keys. Arrays are automatically converted to maps by converting the numeric keys to strings first.

Note that the JSON format imposes additional restrictions, including the following characters which can corrupt the settings file:

  • Backslashes (\) in keys or values, in particular escaped quotes (\").
  • Newlines (\n) in keys.
  • Quotes (") in keys.
  • Periods (.) in keys.

This call can silently fail if multiple instances of the same plugin are actively reading and writing data. If your plugin expects to write to settings frequently, you may check that the data has been properly written by calling Plugin:GetSetting().

パラメータ

key: string
value: Variant

戻り値

void

コードサンプル

Plugin:GetSetting and Plugin:SetSetting

local RAN_BEFORE_KEY = "RunBefore"
local hasRunBefore = plugin:GetSetting(RAN_BEFORE_KEY)
if hasRunBefore then
print("Welcome back!")
else
print("Thanks for installing this plugin!")
plugin:SetSetting(RAN_BEFORE_KEY, true)
end

StartDrag

void
プラグインのセキュリティ

StartDrag initiates a drag action using a dictionary of parameters. The parameters are as follows:

NameTypeDefaultDescription
Senderstring"" Identifies the source of the drag action to the drop target
MimeTypestring"" The MIME type of Data.
Datastring"" Information about the drag action, for example what is being dragged. Should be used by the drop target.
MouseIconContent"" The icon to use for the mouse cursor during the drag. If empty, uses the default cursor.
DragIconContent"" An image to render under the mouse cursor during the drag. This should represent the item being dragged.
HotSpotVector2Vector2.new(0, 0) The pixel offset from the top-left where the cursor should "hold" the DragIcon.

See also:

パラメータ

dragData: Dictionary

戻り値

void

コードサンプル

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
local dragTargetWidget = plugin:CreateDockWidgetPluginGui("Drop Target", widgetInfo)
dragTargetWidget.Title = "Drop Target"
-- This TextLabel will display what was dropped
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Drop here..."
textLabel.Parent = dragTargetWidget
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)
プラグインのセキュリティ

Unions the given parts and returns the resulting UnionOperation.

パラメータ

objects: Instances

戻り値

CreateDockWidgetPluginGui

イールド
プラグインのセキュリティ

CreateDockWidgetPluginGui creates a new DockWidgetPluginGui from the given DockWidgetPluginGuiInfo. The first parameter, pluginGuiId, should be a unique and consistent string. It is used to save the state of the widget's dock state and other internal details.

パラメータ

pluginGuiId: string

A unique and consistent identifier used to storing the widget's dock state and other internal details.

dockWidgetPluginGuiInfo: DockWidgetPluginGuiInfo

Describes the DockWidgetPluginGui to create (initial state, size, etc).


戻り値

コードサンプル

Widget GUI Text Button

-- Create new 'DockWidgetPluginGuiInfo' object
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float, -- Widget will be initialized in floating panel
true, -- Widget will be initially enabled
false, -- Don't override the previous enabled state
200, -- Default width of the floating window
300, -- Default height of the floating window
150, -- Minimum width of the floating window (optional)
150 -- Minimum height of the floating window (optional)
)
-- Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
local testButton = Instance.new("TextButton")
testButton.BorderSizePixel = 0
testButton.TextSize = 20
testButton.TextColor3 = Color3.new(1, 0.2, 0.4)
testButton.AnchorPoint = Vector2.new(0.5, 0.5)
testButton.Size = UDim2.new(1, 0, 1, 0)
testButton.Position = UDim2.new(0.5, 0, 0.5, 0)
testButton.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton.Text = "Click Me"
testButton.Parent = testWidget

ImportFbxAnimation

イールド
プラグインのセキュリティ

This function prompts the user to open a .fbx animation file that can be loaded onto the rigModel, then proceeds to insert the animation as a KeyframeSequence in the Workspace.

パラメータ

rigModel: Instance
isR15: bool
既定値: true

戻り値

ImportFbxRig

イールド
プラグインのセキュリティ

Prompts the user to open a .fbx file, uploads the individual components of the model as meshes, and generates a character rig for use in animation, which is loaded into the Workspace.

パラメータ

isR15: bool
既定値: true

戻り値

PromptForExistingAssetId

イールド
プラグインのセキュリティ

Opens a window in Roblox Studio, which prompts the user to select an asset based on the assetType specified. Returns what assetId was selected, or -1 if the window was closed.

パラメータ

assetType: string

戻り値

PromptSaveSelection

イールド
プラグインのセキュリティ

Prompts the user to save their current selection with the specified file name. Returns true if the user did save the file.

パラメータ

suggestedFileName: string
既定値: ""

戻り値

イベント

Deactivation

プラグインのセキュリティ

Fired when the Plugin is deactivated. This occurs when either the plugin code calls Plugin:Deactivate(), or because some other plugin called Plugin:Activate(), which forces all other plugins to lose their active state.

See also:

  • Plugin.Unloading, fires immediately before the plugin is unloaded or reloaded via uninstallation, deactivation, or updating

Unloading

プラグインのセキュリティ

This event fires immediately before the Plugin stops running. Plugins are unloaded when disabled, uninstalled, about to be updated, or when the place is closing.

It enables a plugin to clean up after itself before its scripts stop running, e.g. to remove unnecessary instances from the DataModel. If a plugin does not clean up properly, the old copies will remain. When this occurs, users may be forced to close and reopen the place which is a bad user experience.

Plugin-related instances such as PluginToolbarButtons, DockWidgetPluginGuis, and PluginGuis are automatically cleaned up when the plugin is unloaded so there is no need to remove them.