插件 是負責創建基本 Studio 視窗、插件工具欄、插件按鈕等的主要對象。這是一種自訂添加到 Studio 的功能,可新增不通常包含的行為和功能。插件 對象可以通過在 執行為外掛程式的全球參考來訪問 中的全球參考。
範例程式碼
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 : boolean):PluginAction
創建一個 PluginAction ,這是一個在 Roblox Studio 中代表一般可執行行動的對象,沒有直接相關的 Toolbar 或 Enum.Button 。
創建新的插件選單。
創建一個新的 PluginToolbar 使用指定名稱。
停用外掛程式。
返回使用者在 Studio 中設定在模型標籤下的 Enum.JointCreationMode。
返回一個 Mouse 可在插件啟用時使用的方法。
返回目前選擇的 Enum.RibbonTool 。
使用指定的鍵取回先前存儲的值,或 nil 如果指定的鑰匙不存在。
如果此插件目前已啟用,且已通過 Plugin:Activate() 函數啟用,則返回真值。
如果此插件目前使用獨家滑鼠,在使用 Plugin:Activate() 函數後啟用,則返回真值。
否認指定的零件,並返回結果的否認操作。
用於在 Roblox Studio 中開啟指定的腳本實例在編輯器窗口,在指定行。如果沒有線提供為參數,它將默認為 1。
開啟上下文幫助窗口到連結到的wiki頁面。url
開啟使用者當前選擇的上傳窗口。
啟用指定的 Roblox Studio 工具。
分開指定的聯繫操作,並返回結果的零件。
儲存給定值以供稍後使用,在給定的鍵匙下會持續存在,即使 Studio 已關閉。
開始拖動操作,給予一個參數字典。
結合指定的零件,並返回結果的聯繫操作。
- CreateDockWidgetPluginGui(pluginGuiId : string,dockWidgetPluginGuiInfo : DockWidgetPluginGuiInfo):DockWidgetPluginGui
創建一個 DockWidgetPluginGui ,給予一個 DockWidgetPluginGuiInfo 。
提示用戶打開可以加載到 rigModel 的 .fbx 動畫文件,然後進行插入動畫為 KeyframeSequence 在 Workspace 。
提示用戶打開 .fbx 文件,上傳模型的個別組件作為網格,並生成用於動畫的角色骨架,該骨架被載入 Workspace 。
在 Roblox Studio 中開啟一個窗口,提示用戶根據指定的 assetType 選擇資產。返回選擇了哪個資產ID,或-1如果窗口已關閉。
提示用戶儲存目前選擇的文件以指定的文件名稱。如果用戶儲存了文件,返回真值;否則返回假值。
屬性
方法
CreatePluginAction
參數
返回
範例程式碼
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
參數
返回
範例程式碼
-- 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
參數
返回
範例程式碼
plugin:CreateToolbar("ExampleToolbar")
Deactivate
返回
GetMouse
返回
範例程式碼
local mouse = plugin:GetMouse()
local function button1Down()
print("Button 1 pressed from PluginMouse")
end
mouse.Button1Down:Connect(button1Down)
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
參數
返回
範例程式碼
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
Negate
參數
返回
OpenScript
參數
返回
範例程式碼
local newScript = Instance.new("Script")
newScript.Parent = workspace
plugin:OpenScript(newScript)
OpenWikiPage
參數
返回
範例程式碼
plugin:OpenWikiPage("API:Class/BasePart")
SaveSelectedToRoblox
返回
Separate
參數
返回
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
參數
返回
範例程式碼
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
參數
返回
範例程式碼
-- 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