Plugin Gui
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm tắt
Phương Pháp
BindToClose(function: function):() |
Sự Kiện
PluginDragDropped(dragData: Dictionary):RBXScriptSignal |
PluginDragEntered(dragData: Dictionary):RBXScriptSignal |
PluginDragLeft(dragData: Dictionary):RBXScriptSignal |
PluginDragMoved(dragData: Dictionary):RBXScriptSignal |
Thành viên kế thừa
4 thành viên kế thừa từ LayerCollector
12 thành viên kế thừa từ GuiBase2d
58 thành viên kế thừa từ Instance
6 thành viên kế thừa từ Object
Được kế thừa bởi
Tài Liệu Tham Khảo API
Thuộc Tính
Phương Pháp
Bind To Close
Get Relative Mouse Position
Lợi Nhuận
Mẫu mã
PluginGui:GetRelativeMousePosition
local RunService = game:GetService("RunService")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
true,
false, -- Trạng thái kích hoạt, ghi đè
200,
300, -- Kích thước
150,
150 -- Kích thước tối thiểu
)
local testWidget = plugin:CreateDockWidgetPluginGuiAsync("TestWidget", widgetInfo)
function update()
local v2 = testWidget:GetRelativeMousePosition()
testWidget.Title = ("(%d, %d)"):format(v2.x, v2.y)
end
RunService.Stepped:Connect(update)
update()Sự Kiện
Plugin Drag Dropped
Tham Số
Mẫu mã
Plugin Kéo và Thả
assert(plugin, "Kịch bản này phải được chạy như một plugin Studio")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGuiAsync("Nguồn Kéo", widgetInfo)
dragSourceWidget.Title = "Nguồn Kéo"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Xin chào, kéo plugin"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.fromOffset(0, 32)
dragButton.Text = "Chỉnh sửa văn bản ở trên, sau đó bắt đầu kéo ở đây"
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)
-- Widget này sẽ nhận các thả
local dragTargetWidget = plugin:CreateDockWidgetPluginGuiAsync("Mục Tiêu Thả", widgetInfo)
dragTargetWidget.Title = "Mục Tiêu Thả"
-- TextLabel này sẽ hiển thị những gì đã được thả
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.fromScale(1, 1)
textLabel.Text = "Thả ở đây..."
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)Plugin Drag Entered
Tham Số
Mẫu mã
Plugin Kéo và Thả
assert(plugin, "Kịch bản này phải được chạy như một plugin Studio")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGuiAsync("Nguồn Kéo", widgetInfo)
dragSourceWidget.Title = "Nguồn Kéo"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Xin chào, kéo plugin"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.fromOffset(0, 32)
dragButton.Text = "Chỉnh sửa văn bản ở trên, sau đó bắt đầu kéo ở đây"
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)
-- Widget này sẽ nhận các thả
local dragTargetWidget = plugin:CreateDockWidgetPluginGuiAsync("Mục Tiêu Thả", widgetInfo)
dragTargetWidget.Title = "Mục Tiêu Thả"
-- TextLabel này sẽ hiển thị những gì đã được thả
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.fromScale(1, 1)
textLabel.Text = "Thả ở đây..."
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)Plugin Drag Left
Tham Số
Mẫu mã
Plugin Kéo và Thả
assert(plugin, "Kịch bản này phải được chạy như một plugin Studio")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGuiAsync("Nguồn Kéo", widgetInfo)
dragSourceWidget.Title = "Nguồn Kéo"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Xin chào, kéo plugin"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.fromOffset(0, 32)
dragButton.Text = "Chỉnh sửa văn bản ở trên, sau đó bắt đầu kéo ở đây"
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)
-- Widget này sẽ nhận các thả
local dragTargetWidget = plugin:CreateDockWidgetPluginGuiAsync("Mục Tiêu Thả", widgetInfo)
dragTargetWidget.Title = "Mục Tiêu Thả"
-- TextLabel này sẽ hiển thị những gì đã được thả
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.fromScale(1, 1)
textLabel.Text = "Thả ở đây..."
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)Plugin Drag Moved
Window Focused
Mẫu mã
Phát hiện trạng thái tiêu điểm của PluginGui
local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGuiAsync("TestWidget", info)
local function onFocusReleased()
widget.Title = "Tôi không có tiêu điểm :("
end
local function onFocused()
widget.Title = "Tôi có tiêu điểm :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)Window Focus Released
Mẫu mã
Phát hiện trạng thái tiêu điểm của PluginGui
local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGuiAsync("TestWidget", info)
local function onFocusReleased()
widget.Title = "Tôi không có tiêu điểm :("
end
local function onFocused()
widget.Title = "Tôi có tiêu điểm :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)