学习
引擎类
PluginGui
无法创建
未复制

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处



API 参考
属性
Title
读取并联
功能: UI
PluginGui.Title:string

方法
BindToClose
功能: UI
PluginGui:BindToClose(function:function):()
参数
function:function
默认值:"nil"
返回
()

GetRelativeMousePosition
插件安全性
功能: UI
PluginGui:GetRelativeMousePosition():Vector2
返回
代码示例
插件图形用户界面:获取相对鼠标位置
local RunService = game:GetService("RunService")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
true,
false, -- 启用状态,覆盖
200,
300, -- 大小
150,
150 -- 最小大小
)
local testWidget = plugin:CreateDockWidgetPluginGuiAsync("测试小部件", widgetInfo)
function update()
local v2 = testWidget:GetRelativeMousePosition()
testWidget.Title = ("(%d, %d)"):format(v2.x, v2.y)
end
RunService.Stepped:Connect(update)
update()

活动
PluginDragDropped
插件安全性
功能: UI
PluginGui.PluginDragDropped(dragData:Dictionary):RBXScriptSignal
参数
dragData:Dictionary
代码示例
插件拖放
assert(plugin, "此脚本必须作为 Studio 插件运行")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGuiAsync("拖动源", widgetInfo)
dragSourceWidget.Title = "拖动源"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "你好,插件拖动"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "编辑上面的文本,然后在这里开始拖动"
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)
-- 这个小部件将接收放置
local dragTargetWidget = plugin:CreateDockWidgetPluginGuiAsync("放置目标", widgetInfo)
dragTargetWidget.Title = "放置目标"
-- 这个 TextLabel 将显示被放置的内容
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "放置在这里..."
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)

PluginDragEntered
插件安全性
功能: UI
PluginGui.PluginDragEntered(dragData:Dictionary):RBXScriptSignal
参数
dragData:Dictionary
代码示例
插件拖放
assert(plugin, "此脚本必须作为 Studio 插件运行")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGuiAsync("拖动源", widgetInfo)
dragSourceWidget.Title = "拖动源"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "你好,插件拖动"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "编辑上面的文本,然后在这里开始拖动"
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)
-- 这个小部件将接收放置
local dragTargetWidget = plugin:CreateDockWidgetPluginGuiAsync("放置目标", widgetInfo)
dragTargetWidget.Title = "放置目标"
-- 这个 TextLabel 将显示被放置的内容
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "放置在这里..."
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)

PluginDragLeft
插件安全性
功能: UI
PluginGui.PluginDragLeft(dragData:Dictionary):RBXScriptSignal
参数
dragData:Dictionary
代码示例
插件拖放
assert(plugin, "此脚本必须作为 Studio 插件运行")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGuiAsync("拖动源", widgetInfo)
dragSourceWidget.Title = "拖动源"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "你好,插件拖动"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "编辑上面的文本,然后在这里开始拖动"
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)
-- 这个小部件将接收放置
local dragTargetWidget = plugin:CreateDockWidgetPluginGuiAsync("放置目标", widgetInfo)
dragTargetWidget.Title = "放置目标"
-- 这个 TextLabel 将显示被放置的内容
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "放置在这里..."
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)

PluginDragMoved
插件安全性
功能: UI
PluginGui.PluginDragMoved(dragData:Dictionary):RBXScriptSignal
参数
dragData:Dictionary

WindowFocused
插件安全性
功能: UI
PluginGui.WindowFocused():RBXScriptSignal
代码示例
检测 PluginGui 聚焦状态
local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGuiAsync("测试小部件", info)
local function onFocusReleased()
widget.Title = "我不在焦点中 :("
end
local function onFocused()
widget.Title = "我在焦点中 :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)

WindowFocusReleased
插件安全性
功能: UI
PluginGui.WindowFocusReleased():RBXScriptSignal
代码示例
检测 PluginGui 聚焦状态
local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGuiAsync("测试小部件", info)
local function onFocusReleased()
widget.Title = "我不在焦点中 :("
end
local function onFocused()
widget.Title = "我在焦点中 :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。