PluginGui

显示已弃用

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

无法创建
未复制

PluginGui 是允许在各种 Roblox Studio 小工具中显示 GuiObjects 的抽象类型 GUI。目前唯一可用的插件类型是 DockWidgetPluginGui ,但未来可能会有更多!

概要

属性

继承自LayerCollector属性继承自GuiBase2d属性

方法

活动

继承自GuiBase2d活动

属性

Title

读取并联

显示在 PluginGui 上方的标题。默认为空字符串。

方法

BindToClose

()

这个函数将函数绑定到 PluginGui 关闭按钮,覆盖默认行为。

默认情况下,当用户单击右上角的 "x" 按钮时, 属性将设置为 false ,关闭窗口。当使用 BindToClose 绑定自定义函数时,该行为被覆盖,允许您检查用户真正想要关闭窗口还是给他们一个保存工作的机会。

由于默认关闭行为被此函数覆盖,因此您需要配置 PluginGui 手动关闭,通过设置 PluginGui.Enabledfalse 来关闭。例如,在下面的代码片段中,用户需要单击确认按钮来关闭 GUI:


local closing = false
pluginGui:BindToClose(function()
-- 确保我们还没有做出按钮
if closing then
return
end
closing = true
-- 创建确认按钮
local confirmButton = Instance.new("TextButton")
confirmButton.AnchorPoint = Vector2.new(0.5, 0.5)
confirmButton.Size = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.Position = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.BackgroundColor3 = Color3.new(1, 0, 0)
confirmButton.Text = "Close?"
confirmButton.Parent = pluginGui
-- 倾听点按
confirmButton.Activated:Connect(function()
-- 关闭 gui
pluginGui.Enabled = false
-- 移除确认按钮
confirmButton:Destroy()
end)
end)

您可以调用 BindToClose 无参数来“解除绑定”并恢复上述描述的默认行为。例如:


pluginGui:BindToClose()

还见:

参数

function: function

用于绑定关闭按钮的函数。如果没有指定函数,则任何之前指定的函数都将被解除绑定。

默认值:"nil"

返回

()

GetRelativeMousePosition

插件安全性

获取相对鼠标位置返回鼠标相对左上角的 PluginGui 位置。返回的值只会在 PluginGui 上开始鼠标输入或鼠标当前正在悬停窗口上时才会发生变化。


返回

鼠标对插件贵的屏幕位置以像素为单位。

代码示例

PluginGui:GetRelativeMousePosition

local RunService = game:GetService("RunService")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
true,
false, -- Enabled state, override
200,
300, -- Size
150,
150 -- Minimum size
)
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
function update()
local v2 = testWidget:GetRelativeMousePosition()
testWidget.Title = ("(%d, %d)"):format(v2.x, v2.y)
end
RunService.Stepped:Connect(update)
update()

活动

PluginDragDropped

插件安全性

插件拖动丢失 在用户释放鼠标时触发,该鼠标在由 PluginGui 启动的拖动操作期间处于 Plugin:StartDrag() 状态。

还见:

参数

dragData: Dictionary

代码示例

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".

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)

PluginDragEntered

插件安全性

插件拖入 在用户的鼠标进入 期间启动的拖动操作开始时发生。

此事件对于在插件菜单上显示一个“在此处拖动”用户界面有用,其中拖动操作可以丢弃。这样的用户界面应该在 PluginDragLeftPluginDragDropped 触发射时隐藏。

还见:

参数

dragData: Dictionary

数据的副本最初传送到 Plugin:StartDrag()


代码示例

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".

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)

PluginDragLeft

插件安全性

插件拖动左侧 在用户的鼠标在开始拖动操作后离开 PluginGui 期间发生,由 Plugin:StartDrag() 启动。

此事件和 PluginDragDropped 有助于隐藏在 PluginGuis 上的“拖放到此”用户界面,其中拖动操作可以被丢弃。这样的用户界面应该在 PluginDragEntered 发生时显示。

还见:

参数

dragData: Dictionary

数据的副本最初传送到 Plugin:StartDrag()


代码示例

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".

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)

PluginDragMoved

插件安全性

插件拖动移动 在用户的鼠标在开始拖动操作后移动到 PluginGui 内发生,当 Plugin:StartDrag() 启动的拖动操作开始时。

还见:

参数

dragData: Dictionary

WindowFocusReleased

插件安全性

窗口焦点释放 在用户停止与插件贵的窗口互动时立即发生,通常通过单击窗口外的某些内容来实现。这些功能与类似名称的 UserInputService.WindowFocusReleased 事件相似。

如果焦点移至另一个 PluginGui 而用户拥有此 PluginGui 在焦点上,则此事件在其他人的 WindowFocused 事件之前发生。然而,如果主游戏窗口正在被聚焦,此事件将在 之后发射 UserInputService.WindowFocused .


代码示例

This code sample demonstrates how the focus state of a PluginGui can be tracked using the WindowFocused() and WindowFocusReleased() events. It changes the Title() as the focus state changes.

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)

WindowFocused

插件安全性

窗口聚焦 在用户开始与 PluginGui 窗口互动时立即发射,通常通过单击它来启动。这些功能与类似名称的 UserInputService.WindowFocused 事件相似。它在任何 GuiObject.InputBegan 与鼠标按钮相关的事件发生之前发射。

如果另一个 PluginGui 处于焦点,用户专注于此 PluginGui,那么此事件在另一个的 WindowFocusReleased 事件之后发生。然而,如果主游戏窗口处于焦点,此事件会在 之后发射 UserInputService.WindowFocusReleased .


代码示例

This code sample demonstrates how the focus state of a PluginGui can be tracked using the WindowFocused() and WindowFocusReleased() events. It changes the Title() as the focus state changes.

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)