概要
方法
BindToClose(function: function):() |
活動
PluginDragDropped(dragData: Dictionary):RBXScriptSignal |
PluginDragEntered(dragData: Dictionary):RBXScriptSignal |
PluginDragLeft(dragData: Dictionary):RBXScriptSignal |
PluginDragMoved(dragData: Dictionary):RBXScriptSignal |
API 參考
屬性
方法
GetRelativeMousePosition
返回
範例程式碼
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
參數
範例程式碼
插件拖放
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
參數
範例程式碼
插件拖放
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
參數
範例程式碼
插件拖放
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)WindowFocused
範例程式碼
檢測 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
範例程式碼
檢測 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)