插件 是创建基础 Studio 小组件、插件工具栏、插件按钮等的主要对象。它是 Studio 的自定义添加在,它添加新的行为和功能, которые通常不包含在正常 Studio 中。插件对象可以通过 Global.RobloxGlobals.ugin 全球引用在一个 Class.Script</
代码示例
The plugin global reference is not passed to ModuleScripts within the plugin. In order to use it in a ModuleScript, you must explicitly pass it as seen in the example below.
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()
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
概要
属性
返回用户在Collisions下在模型标签下是否启用的模式。
返回 Studio 中用户设置的网格包裹尺寸。
方法
将调用插件的状态设置为“激活”。
- CreatePluginAction(actionId : string,text : string,statusTip : string,iconName : string,allowBinding : bool):PluginAction
创建一个 PluginAction ,这是一个代表 Roblox Studio 中的通用执行可能的对象,没有直接关联的 Toolbar 或 Enum.Button 。
创建一个新的插件菜单。
创建一个名为 PluginToolbar 的新 。
禁用插件。
返回 Enum.JointCreationMode 用户在 Studio 下设置的模型标签下的设置。
返回一个 Mouse 可以在插件激活时使用。
返回当前选择的 Enum.RibbonTool 。
使用指定的键恢复以前存储的值,或使用 nil 恢复指定的钥匙不存在的情况下。
如果此插件当前已激活,返回 true,这是通过 Plugin:Activate() 函数激活后。
返回 true 如果此插件当前使用独特鼠标,并且通过 Plugin:Activate() 函数激活后。
否定所给出的零件,并且返回所产生的否定操作。
用于在 Roblox Studio 中打开指定的脚本实例,在指定的行中。如果没有行作为参数,它将默认为 1。
打开上下文帮助窗口到 wiki 页面,链接到。
打开用户当前选择的上传窗口。
激活指定的 Roblox Studio 工具。
分离给定的联盟操作和返回结果部分。
在指定的键匙下保存给定的值,即使工作室关闭后,值也会持续存在。
启动一个给予参数典型的拖动操作。
将给定的零件联合到一起,并且返回结果的 UnionOperation。
- CreateDockWidgetPluginGui(pluginGuiId : string,dockWidgetPluginGuiInfo : DockWidgetPluginGuiInfo):DockWidgetPluginGui
创建一个 DockWidgetPluginGui 给予一个 DockWidgetPluginGuiInfo。
提示用户打开一个 .fbx 动画文件,可以加载到 rigModel 上,然后进行插入动画作为 KeyframeSequence 在 Workspace 上。
提示用户打开一个 .fbx 文件,上传模型的个体组件为网格,并生成一个角色网格以便在动画中使用,它被加载到 Workspace 中。
在 Roblox Studio 中打开一个窗口,用户必须选择根据指定的 assetType 选择资产。返回以前选择的资产Id 或 -1 如果窗口已关闭。
提示用户保存当前选择使用指定的文件名。如果用户保存了文件,则返回 true。
活动
发生插件被禁用时。
立即在 Plugin 停止运行之前发射。
属性
方法
Activate
此函数将调用插件的状态设置为“激活”。激活插件可以通过 Plugin:GetMouse() 方法实现鼠标控制。
在任何时间,有 0 或 1 个已激活的插件。激活一个插件会使所有其他插件无效 (它们将收到一个 Plugin.Deactivation 事件).
还请参阅:
- Plugin:IsActivatedWithExclusiveMouse() , 如果这个插件当前使用独家鼠标时返回 true,后果过此函数的激活
- Plugin.Unloading,即插件被卸载或重新加载时立即触发
参数
一个Boolean,指定是否使用独特的鼠标激活插件。如果是真的,一个 PluginMouse 可以通过 Plugin:GetMouse() 获取。
返回
CreatePluginAction
此函数创建一个 PluginAction ,这是一个代表 Roblox Studio 中的通用执行可能的对象,无需直接关联 Toolbar 或 Enum.Button . 在 Roblox Studio 中,它们可以在 2>文件 → 高级 → 自定义快捷方式…2> 下获得键盘快捷方式,还
当发生某个事件时,PluginAction.Triggered 事件已被触发。
为了使插件动作如预期般运行,它们必须使用此函数。
还请参阅:
- PluginMenu , 上下文菜单, 可以在 Studio 中显示一个列表 插件动作 和支持子菜单
- Plugin:CreatePluginMenu(),创建一个插件菜单
参数
必须是唯一的字符串,用于识别其他人的插件行动。
显示操动作的名称。
显示操动作的描述。
用于显示插件的图标的名称。
Class.PluginAction 是否会被隐藏在 Studio 的快捷键查看图中。 有助于上下文操作。 默认为 true。
返回
代码示例
This code sample visualizes how to create a PluginAction. These must be created using the Plugin:CreatePluginAction() method in order to work.
In order to work as expected, the code block must but pasted into the Command Bar, but only once. Consecutive attempts at executing the code in the Command Bar will result in an error because a plugin cannot create more than one PluginMenu with the same ID.
When the created action is bound and Triggered, it outputs Hello world!.
local pluginAction = plugin:CreatePluginAction(
"HelloWorldAction",
"Hello World",
"Prints a 'Hello world!'",
"rbxasset://textures/sparkle.png",
true
)
pluginAction.Name = "Test Action"
local function actionTriggered()
print("Hello world!")
end
pluginAction.Triggered:Connect(actionTriggered)
CreatePluginMenu
此函数创建一个新的 PluginMenu ,这是 Studio 中显示列表的 PluginActions 和支持子菜单的上下文菜单。
为了让插件菜单正常运行,它们必须使用此函数。
还请参阅:
- Plugin:CreatePluginAction(),创建一个插件行动
- PluginMenu.Title,用作子菜单时显示的文本
- PluginMenu.Icon,用作子菜单显示的图标
- PluginMenu:AddAction() , 将给定的行动添加到菜单
- PluginMenu:AddNewAction() , 创建一个临时行动,它将隐藏在 Studio 自定义快捷键窗口中
- PluginMenu:AddMenu() , 添加了给出的菜单作为分隔符
- PluginMenu:AddSeparator() ,在菜单中添加分隔符
- PluginMenu:Clear() , 清除菜单
- PluginMenu:ShowAsync() ,将菜单显示在鼠标指针上。在选择一个项目或关闭菜单时生成。选择的操作触发其触发事件
参数
返回
代码示例
This code sample visualizes how PluginMenus and PluginActions behave when created for a Plugin. Outside of this example, you should not parent the plugin or its functional components to the experience's workspace.
In order to work as expected, the code block must but pasted into the Command Bar, but only once. Consecutive attempts at executing the code in the Command Bar will result in an error because a plugin cannot create more than one PluginMenu with the same ID.
After executing the code, changing the created BoolValue in the experience's workspace opens the plugin's menus. Selecting an action from the menus the function connected to the trigger signal.
-- This code can be pasted into the command bar, but only once
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
创建工具栏 创建Toolbar 函数创建一个新的 PluginToolbar 用指定的名称。 工具栏可以用来创建插件按钮。
参数
工具栏上的可见文本,标记包含在其中的按钮群。
返回
代码示例
This code creates a toolbar with the name "ExampleToolbar".
plugin:CreateToolbar("ExampleToolbar")
Deactivate
关闭插件。如果插件已被激活,这将使得 PluginMouse 联合的关系解除
还请参阅:
- Plugin:Activate(),将调用插件的状态设置为“激活”
- Plugin.Deactivation,发生在插件被禁用时
- Plugin.Unloading,即插件被卸载或重新加载时立即触发
返回
GetMouse
获取鼠标 返回一个 PluginMouse 可以在插件激活过程中使用的。
返回
代码示例
This code would print Button 1 pressed from PluginMouse each time the mouse's left button was clicked.
local mouse = plugin:GetMouse()
local function button1Down()
print("Button 1 pressed from PluginMouse")
end
mouse.Button1Down:Connect(button1Down)
GetSelectedRibbonTool
选择RibbonTool 将返回当前选择的 Enum.RibbonTool 。它返回一个枚列表,对应特定工具。 此操作将返回是否通过 Plugin:SelectRibbonTool() 手动或程序选择工具。
返回
代码示例
This code must be run from a plugin. This code selects the move tool, checks which tool is selected, then prints out to the console which tool is selected. SelectRibbonTool will not return the value until the next frame.
plugin:SelectRibbonTool(Enum.RibbonTool.Move, UDim2.new())
task.wait() -- wait for next frame
local selectedRibbonTool = plugin:GetSelectedRibbonTool()
print("The selected RibbonTool is", selectedRibbonTool)
GetSetting
使用指定的键恢复以前存储的值,或使用 nil 恢复指定的钥匙不存在的情况下。
因为同一个插件的多个实例可以同时运行(例如,如果多个 Studio 窗口打开),因此您不应该依赖此值在过时保持相同。其他插件实例可以随时更新设置。
此调用可以静默失败并返回 nil 如果多个实例的同一个插件正在读取和写入数据。如果您的插件期望经常写入设置,您应该在短时间后重新检查此调用从返回值来区分是否存在设置暂时不可用或不存在。
参数
返回
代码示例
The below example would print the value saved to the key FirstTime. If the key doesn't exist, it would print nil.
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
IsActivatedWithExclusiveMouse
此函数返回 true 如果此插件当前使用独家鼠标,并且通过 Plugin:Activate() 函数激活后。如果返回 true,一个 PluginMouse 可以通过 Plugin:GetMouse() 获取。
还请参阅:
- Plugin.Deactivation,发生在插件被禁用时
- Plugin.Unloading,即插件被卸载或重新加载时立即触发
返回
当前插件是否使用独家鼠标。
Negate
否定所给出的零件,并且返回所产生的否定操作。
参数
返回
OpenScript
用于在 Roblox Studio 中打开指定的脚本实例,在指定的行中。如果没有行作为参数,它将默认为 1。
参数
返回
代码示例
The following would open a newly created Script in Workspace, assuming the variable "Plugin" was already declared.
local newScript = Instance.new("Script")
newScript.Parent = workspace
plugin:OpenScript(newScript)
OpenWikiPage
打开上下文帮助窗口到 wiki 页面,链接到。
参数
返回
代码示例
The following, when executed in a plugin, will open the BasePart API page in the context help.
plugin:OpenWikiPage("API:Class/BasePart")
SaveSelectedToRoblox
打开用户当前选择的上传窗口。
返回
SelectRibbonTool
激活指定的 Roblox Studio 工具。 如果工具打开窗口,位置参数指定在屏幕上该显示在哪里。
注意:
- 对象必须被选择,才能正确运行。
- 修改 position 属性的尺寸会不会影响对话框弹出窗口。
参数
返回
Separate
分离给定的联盟操作和返回结果部分。
参数
返回
SetSetting
在指定的钥匙下保存给定值,以便在以后使用。值会在 Roblox Studio 关闭后仍然持续存在。这些设置以 JSON 格式保存为一个地图,并使用字符串键保存。阵列通过将数字键转换为字符串自动转换为地图。
请注意,JSON 格式会导致额外的限制,包括以下字符,这些字符可能会破坏设置文件:
- 在键或值中的后退栏(\),特别是逃出的引号(\")。
- 键中的新行( \n )。
- 在钥匙中的引用符(").
- 在钥匙中的期间( )。
如果多个实例的同一个插件正在读取和写入数据,这个调用可能会默认失败。如果您的插件期望在频繁写入设置中写入数据,您可以检查数据是否写入为 Plugin:GetSetting() 。
参数
返回
代码示例
This code sample demonstrates use of the Plugin:GetSetting() and Plugin:SetSetting() functions. They detect if a plugin is running for the first time by setting a key. If the key is true, it prints a "welcome back" message; otherwise it prints a "first run" message and sets the key to true.
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
开始拖动 使用参数典典中的拖动行动。参数为:
<tbody><tr><td><b>发送者</b></td><td>字符串</td><td><code>""</code></td><td>将拖动动作的源标记为拖动目标</td></tr><tr><td><b>MimeType</b></td><td>字符串</td><td><code>""</code></td><td>MINE 类型的<b>数据</b>。</td></tr><tr><td><b>数据</b></td><td>字符串</td><td><code>""</code></td><td>关于拖动行动作的信息,例如被拖动的东西。应该由拖动目标使用。</td></tr><tr><td><b>鼠标图标</b></td><td><code>Datatype.Content</code></td><td><code>""</code></td><td>用于拖动时使用的图标。如果是空的,则使用默认曲标。</td></tr><tr><td><b>拖动图标</b></td><td><code>Datatype.Content</code></td><td><code>""</code></td><td>拖动时鼠标指针在下面的图像。这应该代表被拖动的物品。</td></tr><tr><td><b>热点</b></td><td><code>Datatype.Vector2</code></td><td><code>Datatype.Vector2.new(0, 0)</code></td><td>从左上角开始的像素 Offset 从 where <b>拖动图标</b> 。</td></tr></tbody>
名称 | 类型 | 默认 | 描述 |
---|
还请参阅:
参数
返回
代码示例
This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.
To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".
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)
CreateDockWidgetPluginGui
CreateDockWidgetPluginGui 创建一个新的 DockWidgetPluginGui 从给定的 DockWidgetPluginGuiInfo . 第一个参数, 0> uginGuiId0> ,应该是唯一的和一致的字控件串。它用于保存 widget 的 dock 状态和其他内部细节。
参数
用于存储 widget 的控件状态和其他内部详细信息的独特和一致的标识符。
描述DockWidgetPluginGui创建(初始状态、大小等)。
返回
代码示例
This code, when ran inside a Plugin, creates a DockWidgetPluginGui with a simple TextButton.
-- 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
此功能提示用户打开一个可以加载到 rigModel 的 .fbx 动画文件,然后将动画作为 KeyframeSequence 插入在 Workspace 中。
参数
返回
PromptForExistingAssetId
在 Roblox Studio 中打开一个窗口,用户必须选择根据指定的 assetType 选择资产。返回以前选择的资产Id 或 -1 如果窗口已关闭。
参数
返回
活动
Deactivation
Class.Plugin 被禁用时发生。这是因为插件代码调用 Plugin:Deactivate() 或因为其他插件调用 Plugin:Activate(),这使所有其他插件都必须失去其状态。
还请参阅:
- Plugin.Unloading,即插件被卸载或重新加载时立即触发
Unloading
此事件在 Plugin 停止运行即时触发。插件在禁用、未安装、准备更新或关闭时发生。
它使允许插件在脚本停止运行前自动清理, 例如, 从 DataModel 中移除不必要的实例。如果插件未能正确清理, 旧副本将剩下。当这种情况发生时, 用户可能被迫关闭并重新打开这个地方, 这是一个坏用户体验。
如果插件相关实例,例如 PluginToolbarButtons、DockWidgetPluginGuis 和 PluginGuis ,在插件解锁时自动清理,因此不需要将其移除。