PluginGui
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
PluginGui เป็นคลาสที่สังเกตได้สำหรับ GUI ที่อนุญาตให้แสดง GuiObjects ในวิดเจ็ต Roblox Studio ต่างๆในขณะนี้ประเภท PluginGui ที่มีอยู่เพียงอย่างเดียวคือ DockWidgetPluginGui แต่อาจมีเพิ่มเติมในอนาคต!
สรุป
คุณสมบัติ
ชื่อที่แสดงบนเนื้อหาของ PluginGui .
สลับการมองเห็นของสิ่งนี้ LayerCollector .
กำหนดว่าการรีเซ็ต LayerCollector จะเกิดขึ้น (ลบตัวเองและรีโคลนเข้าสู่ตัวละครของผู้เล่น PlayerGui ) ทุกครั้งที่ตัวละครของผู้เล่นเกิดใหม่
ควบคุมวิธีที่ GuiObject.ZIndex จะทำงานกับทุกสายลูกของสิ่งนี้ LayerCollector
อธิบายตำแหน่งจอแสดงจริงขององค์ประกอบ GuiBase2d ในพิกเซล
อธิบายการหมุนหน้าจอที่เกิดขึ้นจริงขององค์ประกอบ GuiBase2d ในองศา
อธิบายขนาดหน้าจอที่เป็นจริงขององค์ประกอบ GuiBase2d ในพิกเซล
เมื่อตั้งค่าเป็น true การแปลท้องถิ่นจะถูกใช้กับ GuiBase2d และบรรดาลูกหลานของมัน
การอ้างอิงถึง LocalizationTable ที่จะใช้เพื่อใช้การแปลงภาษาท้องถิ่นอัตโนมัติกับ GuiBase2d และบรรดาลูกหลานของมัน
ปรับพฤติกรรมการเลือกเกมแพดในทิศทางลง
ปรับพฤติกรรมการเลือกเกมแพดในทิศทางซ้าย
ปรับพฤติกรรมการเลือก gamepad ในทิศทางที่ถูกต้อง
ปรับพฤติกรรมการเลือกเกมแพดในทิศทางขึ้น
อนุญาตให้ปรับแต่งการเคลื่อนไหวการเลือกเกมแพดได้
วิธีการ
ผูกฟังก์ชันกับปุ่มปิด PluginGui เพื่อยกเลิกพฤติกรรมเริ่มต้น
ส่งคืนตำแหน่งของเมาส์เมื่อเทียบกับ PluginGui
อีเวนต์
เกิดไฟไหม้เมื่อผู้ใช้ปล่อยเมาส์ขณะเลื่อนเหนือ PluginGui ระหว่างการลากที่เริ่มต้นโดย Plugin:StartDrag()
จะเกิดไฟไหม้เมื่อเมาส์ของผู้ใช้เข้าสู่ PluginGui ระหว่างการลากที่เริ่มต้นโดย Plugin:StartDrag()
เกิดไฟไหม้เมื่อเมาส์ของผู้ใช้ออกจาก PluginGui ในระหว่างการลากที่เริ่มโดย Plugin:StartDrag()
เกิดไฟไหม้เมื่อเมาส์ของผู้ใช้เคลื่อนที่ภายใน PluginGui ระหว่างการลากที่เริ่มโดย Plugin:StartDrag()
เกิดไฟไหม้เมื่อผู้ใช้หยุดโต้ตอบกับหน้าต่างของ PluginGui
เกิดไฟไหม้เมื่อผู้ใช้เริ่มโต้ตอบกับหน้าต่างของ PluginGui
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
ไฟเมื่อการเลือกเกมแพดย้ายไปที่ ออก หรือเปลี่ยนภายในเชื่อมต่อ GuiBase2d หรือทายาทใดๆ GuiObjects
คุณสมบัติ
วิธีการ
BindToClose
ฟังก์ชันนี้ผูกฟังก์ชันกับปุ่มปิด PluginGui เพื่อยกเลิกพฤติกรรมเริ่มต้น
โดยค่าเริ่มต้นเมื่อผู้ใช้คลิกปุ่ม 'x' ในมุมขวาบนของ PluginGui คุณสมบัติ Enabled จะถูกตั้งค่าเป็น ปิด ปิดหน้าต่างเมื่อฟังก์ชันที่กําหนดเองถูกผูกโดยใช้ BindToClose พฤติกรรมนี้จะถูกเขียนทับ ทําให้คุณสามารถตรวจสอบได้ว่าผู้ใช้ต้องการปิดหน้าต่างจริงๆ หรือให้โอกาสพวกเขาบันทึกงาน
เนื่องจากพฤติกรรมการปิดเริ่มต้นถูกเขียนทับโดยฟังก์ชันนี้คุณจะต้องกำหนดค่า PluginGui ให้ปิดด้วยตนเองโดยการตั้งค่า PluginGui.Enabled เป็น ปิดตัวอย่างเช่นในส่วนตัดต่อด้านล่างผู้ใช้จะต้องคลิกปุ่มยืนยันเพื่อปิด 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()
ดูเพิ่ม:
- Plugin:CreateDockWidgetPluginGui() เพื่อสร้าง PluginGui
- DataModel:BindToClose() ซึ่งสามารถใช้เพื่อผูกฟังก์ชันกับจุดจบของเกมและไม่ควรสับสนกับฟังก์ชันนี้
พารามิเตอร์
ฟังก์ชันที่จะผูกปุ่มปิดกับ หากไม่มีฟังก์ชันที่ระบุไว้ก่อนหน้านี้จะถูกยกเลิกการผูก
ส่งค่ากลับ
GetRelativeMousePosition
ตำแหน่งเมาส์ที่เกี่ยวข้องจะคืนตำแหน่งของเมาส์เมื่อเทียบกับมุมซ้ายบนของ PluginGuiค่าที่ส่งกลับจะเปลี่ยนเฉพาะถ้าการใส่เมาส์เริ่มบน PluginGui หรือถ้าเมาส์กำลังวางอยู่บนหน้าต่างในปัจจุบัน
ส่งค่ากลับ
ตำแหน่งหน้าจอของเมาส์เมื่อเทียบกับ PluginGui ในพิกเซล
ตัวอย่างโค้ด
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
PluginDragDropped จะเกิดขึ้นเมื่อผู้ใช้ปล่อยเมาส์ของพวกเขาบน PluginGui ในระหว่างการลากที่เริ่มต้นโดย 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".
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
PluginDragEntered จะเกิดขึ้นเมื่อเมาส์ของผู้ใช้เข้าสู่ PluginGui ในระหว่างการลากที่เริ่มต้นโดย Plugin:StartDrag()
อีเวนต์นี้มีประโยชน์สำหรับการแสดง UI "วางที่นี่" บน PluginGuis ซึ่งการดรากที่สามารถวางได้UI ดังกล่าวควรถูกซ่อนเมื่อ PluginDragLeft หรือ PluginDragDropped ไฟไหม้
ดูเพิ่ม:
พารามิเตอร์
สำเนาของข้อมูลที่เดิมถูกส่งไปยัง 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".
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
PluginDragLeft จะเกิดขึ้นเมื่อเมาส์ของผู้ใช้ออกจาก PluginGui ในระหว่างการลากที่เริ่มต้นโดย Plugin:StartDrag()
อีเวนต์นี้และ PluginDragDropped มีประโยชน์ในการซ่อน UI "วางที่นี่" บน PluginGuis ซึ่งการดรากสามารถถูกทิ้งได้UI ดังกล่าวควรแสดงเมื่อมีการเรียกไฟ PluginDragEntered
ดูเพิ่ม:
พารามิเตอร์
สำเนาของข้อมูลที่เดิมถูกส่งไปยัง 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".
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
PluginDragMoved จะเกิดขึ้นเมื่อเมาส์ของผู้ใช้เคลื่อนที่ภายใน PluginGui ระหว่างการลากที่เริ่มโดย Plugin:StartDrag() ในระหว่างการลาก
ดูเพิ่ม:
พารามิเตอร์
WindowFocusReleased
WindowFocusReleased จะเริ่มติดไฟทันทีเมื่อผู้ใช้หยุดโต้ตอบกับหน้าต่างของ PluginGui โดยปกติโดยคลิกที่บางสิ่งที่ไม่อยู่ในหน้าต่างฟังก์ชันนี้ทำงานคล้ายกับอีเวนต์ที่มีชื่อคล้ายกัน 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.
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.
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)