學習
引擎類別
PluginGui
無法建立
未複製

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡



API 參考
屬性
Title
平行讀取
功能: UI
PluginGui.Title:string

方法
BindToClose
功能: UI
PluginGui:BindToClose(function:function):()
參數
function:function
預設值:"nil"
返回
()

GetRelativeMousePosition
外掛程式安全性
功能: UI
PluginGui:GetRelativeMousePosition():Vector2
返回
範例程式碼
PluginGui:獲取相對滑鼠位置
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 = "一些拖曳來源",
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 = "一些拖曳來源",
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 = "一些拖曳來源",
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 是我們在美國及其他國家地區的部分註冊與未註冊商標。