Plugin
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ปลั๊กอิน เป็นวัตถุหลักที่รับผิดชอบในการสร้างส่วนประกอบ Studio พื้นฐานเครื่องมือแถบเครื่องมือปลั๊กอินปุ่มปลั๊กอินและอื่น ๆเป็นส่วนเสริมที่กำหนดเองสำหรับ Studio ซึ่งเพิ่มพฤติกรรมและคุณลักษณะใหม่ที่ไม่ได้รวมอยู่ตามปกติวัตถุ ปลั๊กอิน สามารถเข้าถึงได้ผ่านการอ้างอิงทั่วโลกใน ที่ดำเนินการเป็นปลั๊กอิน
ตัวอย่างโค้ด
The plugin global reference is not passed to ModuleScripts within the plugin. In order to use it in a ModuleScript, you must explicitly pass it as seen in the example below.
assert(plugin, "This script must be run as a plugin!")
-- Code beyond this point will execute only if the script is run as a plugin
-- Load the module and pass the plugin reference
local pluginModule = require(script.Parent.PluginModule)
pluginModule:Initialize(plugin)
-- Verify if the plugin reference was initialized
pluginModule:CheckForPluginGlobal()
local pluginModule = {}
local plugin -- Local plugin reference
-- Initialize the plugin reference if not already set
function pluginModule:Initialize(pluginReference: Plugin)
if plugin ~= pluginReference then
plugin = pluginReference
else
error("Plugin is already initialized")
end
end
-- Check if the plugin reference is set and print out appropriate info
function pluginModule:CheckForPluginGlobal()
if plugin ~= nil then
print("Plugin reference is set!")
else
warn("Plugin reference is missing!")
end
end
return pluginModule
สรุป
คุณสมบัติ
คืนว่าผู้ใช้เปิดใช้งาน Collisions ใน Studio ภายใต้แท็บโมเดลหรือไม่
ส่งคืนขนาดการสแน็ปกริดที่ผู้ใช้ตั้งไว้ใน Studio
วิธีการ
ตั้งสถานะของปลั๊กอินที่เรียกใช้เป็นใช้งานแล้ว
- CreatePluginAction(actionId : string,text : string,statusTip : string,iconName : string,allowBinding : boolean):PluginAction
สร้าง PluginAction ซึ่งเป็นวัตถุที่แทนที่การดำเนินการทั่วไปที่สามารถทำได้ใน Roblox Studio โดยไม่มี Toolbar หรือ Enum.Button ที่เกี่ยวข้องโดยตรง
สร้างเมนูปลั๊กอินใหม่
สร้างใหม่ PluginToolbar ด้วยชื่อที่กำหนด
ปิดใช้งานปลั๊กอิน
ส่งคืน Enum.JointCreationMode ที่ผู้ใช้ได้ตั้งค่าไว้ใน Studio ภายใต้แท็บโมเดล
ส่งคืน Mouse ที่สามารถใช้งานได้ในขณะที่ปลั๊กอินใช้งานอยู่
ส่งคืน Enum.RibbonTool กลับ
คีย์nil หากกุญแจที่กำหนดไม่มีอยู่
ส่งคืนจริงหากปลั๊กอินนี้ใช้งานอยู่ในปัจจุบันหลังจากได้รับการเปิดใช้งานผ่านฟังก์ชัน Plugin:Activate()
ส่งคืนค่าจริงหากปลั๊กอินนี้ใช้งานอยู่ในขณะนี้ด้วยเมาส์สุดพิเศษหลังจากที่ถูกเปิดใช้งานผ่านฟังก์ชัน Plugin:Activate()
ปฏิเสธส่วนที่กำหนดและส่งคืนการดำเนินการปฏิเสธที่ได้รับ
ใช้เพื่อเปิดตัวแปรสคริปต์ที่กำหนดในหน้าต่างบรรณาธิการใน Roblox Studio ในบรรทัดที่กำหนดหากไม่มีบรรทัดใดที่ให้เป็นอาร์กิวเมนต์จะเริ่มต้นที่ 1
เปิดหน้าต่างบริบทช่วยเหลือไปยังหน้าวิกิที่มีลิงก์ url
เปิดหน้าต่างอัปโหลดสำหรับการเลือกปัจจุบันของผู้ใช้
เปิดใช้งานเครื่องมือ Roblox Studio ที่กำหนดไว้
แยกการดำเนินการสหภาพที่กำหนดและส่งคืนชิ้นส่วนที่ได้รับ
เก็บค่าที่กำหนดไว้สำหรับใช้ในภายหลังภายใต้กุญแจที่กำหนด ค่าจะยังคงอยู่แม้หลังจากที่ Studio ปิดแล้ว
เริ่มการดำเนินการลากให้ได้รับสารบัญของพารามิเตอร์
รวมส่วนที่กำหนดและ返回การดำเนินการสหภาพที่ได้รับ
- CreateDockWidgetPluginGui(pluginGuiId : string,dockWidgetPluginGuiInfo : DockWidgetPluginGuiInfo):DockWidgetPluginGui
สร้าง DockWidgetPluginGui ที่ได้รับ DockWidgetPluginGuiInfo .
ขอให้ผู้ใช้เปิดไฟล์แอนิเมชัน .fbx ที่สามารถโหลดลงบน rigModel จากนั้นดำเนินการสอดแทรกแอนิเมชันเป็น KeyframeSequence ใน Workspace
เรียกให้ผู้ใช้เปิดไฟล์ .fbx อัปโหลดส่วนประกอบรายบุคคลของโมเดลเป็นเมช และสร้างชุดตัวละครสำหรับใช้ในการแอนิเมชันซึ่งโหลดลงใน Workspace
เปิดหน้าต่างใน Roblox Studio ซึ่งจะขอให้ผู้ใช้เลือกสินทรัพย์ตามที่ assetType กำหนดคืนสิ่งที่ assetId ถูกเลือกหรือ -1 หากหน้าต่างถูกปิด
ขอให้ผู้ใช้บันทึกการเลือกปัจจุบันด้วยชื่อไฟล์ที่ระบุ คืนค่าเป็นจริงหากผู้ใช้บันทึกไฟล์
อีเวนต์
ยิงเมื่อปลั๊กอินถูกปิดใช้งาน
ไฟไหม้ทันทีก่อนที่ Plugin จะหยุดทำงาน
คุณสมบัติ
DisableUIDragDetectorDrags
GridSize
ส่งคืนขนาดการสแน็ปกริดที่ผู้ใช้ตั้งไว้ใน Studio ภายใต้แท็บ รูปแบบ หรือ อวตาร ของแถบเครื่องมือโปรดทราบว่าคุณสมบัตินี้อาจมีข้อผิดพลาดการตัดเลขเล็กน้อย; ตัวอย่างเช่นอาจเป็น 0.0099999997764826 สำหรับการตั้งค่าผู้ใช้ของ 1 หรือ 0.4000000059604645 สำหรับการตั้งค่าผู้ใช้ของ 0.4
IsDebuggable
วิธีการ
Activate
ฟังก์ชันนี้ตั้งสถานะของปลั๊กอินที่เรียกใช้ให้เปิดใช้งาน การเปิดใช้งานปลั๊กอินช่วยให้สามารถควบคุมเมาส์ผ่านวิธี Plugin:GetMouse() ได้
ในเวลาใดก็ได้มีปลั๊กอินที่เปิดใช้งาน 0 หรือ 1การเปิดใช้งานปลั๊กอินจะปิดใช้งานปลั๊กอินอื่น ๆ ทั้งหมด (พวกเขาจะได้รับเหตุการณ์ Plugin.Deactivation )
ดูเพิ่ม:
- Plugin:IsActivatedWithExclusiveMouse() กลับเป็นจริงหากปลั๊กอินนี้ใช้งานอยู่ในขณะนี้ด้วยเมาส์สุดพิเศษหลังจากได้รับการเปิดใช้งานผ่านฟังก์ชันนี้
- Plugin.Unloading ไฟไหม้ทันทีก่อนที่จะปลดหรือโหลดแอปพลิเคชันอีกครั้งผ่านการถอดออก ปิดใช้งาน หรืออัปเดต
พารามิเตอร์
ตัวเลือกเชิงเสียงที่ระบุว่าจะเปิดใช้งานปลั๊กอินด้วยเมาส์สุดพิเศษหรือไม่ หากเป็นจริง, PluginMouse สามารถดึงได้ผ่าน Plugin:GetMouse()
ส่งค่ากลับ
CreatePluginAction
ฟังก์ชันนี้สร้าง PluginAction ซึ่งเป็นวัตถุที่แทนที่การดำเนินการทั่วไปที่สามารถทำได้ใน Roblox Studio โดยไม่มีการเชื่อมโยงโดยตรง Toolbar หรือ Enum.Buttonใน Roblox Studio พวกเขาสามารถได้รับการกำหนดลักษณะลัดแป้นพิมพ์ภายใต้ File → Advanced → Customize Shortcuts… และพวกเขายังสามารถเพิ่มลงในแถบเครื่องมือการเข้าถึงรวดเร็วได้
เมื่อการดำเนินการถูกกระตุ้น การเหตุการณ์ PluginAction.Triggered จะได้รับสัญญาณ
เพื่อให้การดำเนินการของปลั๊กอินทำงานตามที่คาดไว้ พวกเขาต้องถูกสร้างขึ้นโดยใช้ฟังก์ชันนี้
ดูเพิ่ม:
- PluginMenu , เมนูบริบทที่สามารถแสดงใน Studio ซึ่งแสดงรายการของ PluginActions และสนับสนุนสาขาย่อย
- Plugin:CreatePluginMenu() สร้างเมนูปลั๊กอิน
พารามิเตอร์
ต้องเป็นสตริงที่ไม่ซ้ำกันที่ระบุ PluginAction นี้จากคนอื่น
แอ็คชัน
แอ็คชัน
ชื่อไอคอนที่ใช้แสดงปลั๊กอิน
ว่า PluginAction จะถูกซ่อนจากมุมมองลัดของ Studio มีประโยชน์สำหรับการดำเนินการในบริบท ค่าเริ่มต้นคือจริง
ส่งค่ากลับ
ตัวอย่างโค้ด
This code sample visualizes how to create a PluginAction. These must be created using the Plugin:CreatePluginAction() method in order to work.
In order to work as expected, the code block must but pasted into the Command Bar, but only once. Consecutive attempts at executing the code in the Command Bar will result in an error because a plugin cannot create more than one PluginMenu with the same ID.
When the created action is bound and Triggered, it outputs Hello world!.
local pluginAction = plugin:CreatePluginAction(
"HelloWorldAction",
"Hello World",
"Prints a 'Hello world!'",
"rbxasset://textures/sparkle.png",
true
)
pluginAction.Name = "Test Action"
local function actionTriggered()
print("Hello world!")
end
pluginAction.Triggered:Connect(actionTriggered)
CreatePluginMenu
ฟังก์ชันนี้สร้าง PluginMenu ซึ่งเป็นเมนูบริบทที่สามารถแสดงใน Studio ได้ซึ่งแสดงรายการของ PluginActions และสนับสนุนสาขาย่อย
เพื่อให้ PluginMenus ทำงานตามที่คาดไว้ได้ พวกเขาต้องถูกสร้างขึ้นโดยใช้ฟังก์ชันนี้
ดูเพิ่ม:
- PluginAction , วัตถุที่แทนที่การดำเนินการทั่วไปที่สามารถทำได้ใน Roblox Studio โดยไม่มี Toolbar หรือ Enum.Button ที่เกี่ยวข้องโดยตรง
- Plugin:CreatePluginAction() สร้าง PluginAction
- PluginMenu.Title , ข้อความที่จะแสดงเมื่อใช้เป็นเมนูย่อย
- PluginMenu.Icon , ไอคอนที่จะแสดงเมื่อใช้เป็นเมนูย่อย
- PluginMenu:AddAction() เพิ่มการดำเนินการที่กำหนดไว้ในเมนู
- PluginMenu:AddNewAction() สร้างการดำเนินการชั่วคราวที่ซ่อนจากหน้าต่างการปรับแต่งลัดของ Studio
- PluginMenu:AddMenu() เพิ่มเมนูที่กำหนดเป็นตัวแยก
- PluginMenu:AddSeparator() เพิ่มตัวแยกระหว่างรายการในเมนู
- PluginMenu:Clear() , ล้างเมนู
- PluginMenu:ShowAsync() แสดงเมนูที่เคอร์เซอร์ของเมาส์ให้จนกว่าจะมีการเลือกรายการหรือปิดเมนูการดำเนินการที่เลือกจะเปิดการเหตุการณ์ที่กระตุ้นของมัน
พารามิเตอร์
รหัสเฉพาะสำหรับเมนู
ข้อความที่จะแสดงเมื่อใช้เป็นเมนูย่อ
ไอคอนที่จะแสดงเมื่อใช้เป็นเมนูย่อ
ส่งค่ากลับ
ตัวอย่างโค้ด
This code sample visualizes how PluginMenus and PluginActions behave when created for a Plugin. Outside of this example, you should not parent the plugin or its functional components to the experience's workspace.
In order to work as expected, the code block must but pasted into the Command Bar, but only once. Consecutive attempts at executing the code in the Command Bar will result in an error because a plugin cannot create more than one PluginMenu with the same ID.
After executing the code, changing the created BoolValue in the experience's workspace opens the plugin's menus. Selecting an action from the menus the function connected to the trigger signal.
-- This code can be pasted into the command bar, but only once
local pluginMenu = plugin:CreatePluginMenu(math.random(), "Test Menu")
pluginMenu.Name = "Test Menu"
pluginMenu:AddNewAction("ActionA", "A", "rbxasset://textures/loading/robloxTiltRed.png")
pluginMenu:AddNewAction("ActionB", "B", "rbxasset://textures/loading/robloxTilt.png")
local subMenu = plugin:CreatePluginMenu(math.random(), "C", "rbxasset://textures/explosion.png")
subMenu.Name = "Sub Menu"
subMenu:AddNewAction("ActionD", "D", "rbxasset://textures/whiteCircle.png")
subMenu:AddNewAction("ActionE", "E", "rbxasset://textures/icon_ROBUX.png")
pluginMenu:AddMenu(subMenu)
pluginMenu:AddSeparator()
pluginMenu:AddNewAction("ActionF", "F", "rbxasset://textures/sparkle.png")
local toggle = Instance.new("BoolValue")
toggle.Name = "TogglePluginMenu"
toggle.Parent = workspace
local function onToggled()
if toggle.Value then
toggle.Value = false
local selectedAction = pluginMenu:ShowAsync()
if selectedAction then
print("Selected Action:", selectedAction.Text, "with ActionId:", selectedAction.ActionId)
else
print("User did not select an action!")
end
end
end
toggle.Changed:Connect(onToggled)
CreateToolbar
ฟังก์ชัน สร้างแถบเครื่องมือ สร้างแถบใหม่ PluginToolbar ด้วยชื่อที่กำหนด แถบเครื่องมือสามารถใช้สร้างปุ่มปลั๊กอินได้
พารามิเตอร์
ข้อความที่มองเห็นได้บนแถบเครื่องมือซึ่งบอกกลุ่มของปุ่มที่อยู่ภายใน
ส่งค่ากลับ
ตัวอย่างโค้ด
This code creates a toolbar with the name "ExampleToolbar".
plugin:CreateToolbar("ExampleToolbar")
Deactivate
ปิดใช้งานปลั๊กอิน สิ่งนี้จะทำให้ปลั๊กอินที่เกี่ยวข้อง PluginMouse ถูกปิดใช้งานหากมันถูกเปิดใช้งาน
ดูเพิ่ม:
- Plugin:Activate() ตั้งสถานะของปลั๊กอินที่เรียกใช้ให้เปิดใช้งาน
- Plugin.Deactivation ไฟเมื่อปลั๊กอินถูกปิดใช้งาน
- Plugin.Unloading ไฟไหม้ทันทีก่อนที่จะปลดหรือโหลดแอปพลิเคชันอีกครั้งผ่านการถอดออก ปิดใช้งาน หรืออัปเดต
ส่งค่ากลับ
GetMouse
รับเมาส์ ส่งคืน PluginMouse ที่สามารถใช้งานได้ในขณะที่ปลั๊กอินใช้งานอยู่ผ่าน Plugin:Activate()
ส่งค่ากลับ
ตัวอย่างโค้ด
This code would print Button 1 pressed from PluginMouse each time the mouse's left button was clicked.
local mouse = plugin:GetMouse()
local function button1Down()
print("Button 1 pressed from PluginMouse")
end
mouse.Button1Down:Connect(button1Down)
GetSelectedRibbonTool
ได้รับเครื่องมือริบบิ้นที่เลือกแล้วส่งคืนที่เลือกในปัจจุบัน Enum.RibbonToolมันส่งคืน Enum ที่ตรงกับเครื่องมือเฉพาะนี้จะกลับไปว่าเครื่องมือถูกเลือกโดยการคลิกด้วยตนเองหรือโปรแกรมผ่าน Plugin:SelectRibbonTool()
ส่งค่ากลับ
ตัวอย่างโค้ด
This code must be run from a plugin. This code selects the move tool, checks which tool is selected, then prints out to the console which tool is selected. SelectRibbonTool will not return the value until the next frame.
plugin:SelectRibbonTool(Enum.RibbonTool.Move, UDim2.new())
task.wait() -- wait for next frame
local selectedRibbonTool = plugin:GetSelectedRibbonTool()
print("The selected RibbonTool is", selectedRibbonTool)
GetSetting
คีย์nil หากกุญแจที่กำหนดไม่มีอยู่
เนื่องจากตัวอย่างเดียวกันของปลั๊กอินเดียวกันสามารถทำงานได้พร้อมกัน (ตัวอย่างเช่นหากมีหน้าต่าง Studio หลายตัวเปิดอยู่) คุณไม่ควรพึ่งพาค่านี้ให้เหมือนกันตลอดเวลาตัวอย่างปลั๊กอินอื่น ๆ สามารถอัปเดตการตั้งค่าได้ตลอดเวลา
การโทรนี้สามารถล้มเหลวได้อย่างเงียบและส่งคืน nil หากมีตัวอย่างหลายตัวของปลั๊กอินเดียวกันกำลังอ่านและเขียนข้อมูลอยู่หากปลั๊กอินของคุณคาดว่าจะเขียนการตั้งค่าบ่อยๆ คุณควรตรวจสอบค่าที่ส่งกลับจากการโทรนี้หลังจากสักครู่เพื่อแยกแยะระหว่างการตั้งค่าที่ไม่สามารถใช้งานได้ชั่วคราวและการตั้งค่าที่ไม่มีอยู่
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
The below example would print the value saved to the key FirstTime. If the key doesn't exist, it would print nil.
local RAN_BEFORE_KEY = "RanBefore"
local didRunBefore = plugin:GetSetting(RAN_BEFORE_KEY)
if didRunBefore then
print("Welcome back!")
else
plugin:SetSetting(RAN_BEFORE_KEY, true)
print("Welcome! Thanks for installing this plugin!")
end
IsActivated
ฟังก์ชันนี้จะคืนค่าเป็นจริงหากปลั๊กอินนี้ใช้งานอยู่ในปัจจุบันหลังจากได้รับการเปิดใช้งานผ่านฟังก์ชัน Plugin:Activate()
ส่งค่ากลับ
เป็นไบนารีที่ระบุว่าปลั๊กอินมีอยู่ในปัจจุบันหรือไม่
IsActivatedWithExclusiveMouse
ฟังก์ชันนี้จะคืนค่าเป็นจริงหากปลั๊กอินนี้ใช้งานอยู่ในขณะนี้ด้วยเมาส์สุดพิเศษหลังจากได้รับการเปิดใช้งานผ่านฟังก์ชัน Plugin:Activate()หากสิ่งนี้ส่งคืนเป็นจริง, PluginMouse สามารถดึงได้ผ่าน Plugin:GetMouse() .
ดูเพิ่ม:
- Plugin.Deactivation ไฟเมื่อปลั๊กอินถูกปิดใช้งาน
- Plugin.Unloading ไฟไหม้ทันทีก่อนที่จะปลดหรือโหลดแอปพลิเคชันอีกครั้งผ่านการถอดออก ปิดใช้งาน หรืออัปเดต
ส่งค่ากลับ
ว่าส่วนประกอบนี้มีการใช้งานอยู่ในปัจจุบันด้วยเมาส์พิเศษหรือไม่
Negate
ปฏิเสธส่วนที่กำหนดและส่งคืนการดำเนินการปฏิเสธที่ได้รับ
พารามิเตอร์
ส่งค่ากลับ
OpenScript
ใช้เพื่อเปิดตัวแปรสคริปต์ที่กำหนดในหน้าต่างบรรณาธิการใน Roblox Studio ในบรรทัดที่กำหนดหากไม่มีบรรทัดใดที่ให้เป็นอาร์กิวเมนต์จะเริ่มต้นที่ 1
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
The following would open a newly created Script in Workspace, assuming the variable "Plugin" was already declared.
local newScript = Instance.new("Script")
newScript.Parent = workspace
plugin:OpenScript(newScript)
OpenWikiPage
เปิดหน้าต่างบริบทช่วยเหลือไปยังหน้าวิกิที่มีลิงก์ url
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
The following, when executed in a plugin, will open the BasePart API page in the context help.
plugin:OpenWikiPage("API:Class/BasePart")
SaveSelectedToRoblox
เปิดหน้าต่างอัปโหลดสำหรับการเลือกปัจจุบันของผู้ใช้
ส่งค่ากลับ
SelectRibbonTool
เปิดใช้งานเครื่องมือ Roblox Studio ที่ระบุ หากเครื่องมือเปิดหน้าต่าง พารามิเตอร์ตำแหน่งจะระบุตำแหน่งที่ควรแสดงบนหน้าจอ
หมายเหตุ:
- ต้องเลือกวัตถุเพื่อให้สิ่งนี้ทำงานได้อย่างถูกต้อง
- การเปลี่ยนช่องเครื่องชั่งของคุณสมบัติ position จะไม่ส่งผลต่อป๊อปอัพกล่องโต้ตอบ
พารามิเตอร์
ส่งค่ากลับ
Separate
แยกการดำเนินการสหภาพที่กำหนดและส่งคืนชิ้นส่วนที่ได้รับ
พารามิเตอร์
ส่งค่ากลับ
SetSetting
บันทึกค่าที่กำหนดไว้สำหรับใช้ในภายหลังภายใต้กุญแจที่กำหนดค่าจะยังคงอยู่แม้หลังจากที่ Roblox Studio ถูกปิดการตั้งค่าเหล่านี้จะถูกบันทึกในรูปแบบ JSON ในฐานะแผนที่ที่มีกุญแจสตริงค่าเรียงลําดับจะถูกแปลงเป็นแผนที่โดยอัตโนมัติโดยการแปลงคีย์เลขเป็นข้อความก่อน
โปรดทราบว่ารูปแบบ JSON กำหนดข้อจํากัดเพิ่มเติมรวมถึงตัวอักษรต่อไปนี้ซึ่งสามารถทําให้ไฟล์การตั้งค่าเสียได้:
- แบ็คสแลช ( \ ) ในคีย์หรือค่า, โดยเฉพาะอย่างยิ่งคําอ้างอิงที่หลบหนี ( \" )
- บรรทัดใหม่ ( \n ) ในคีย์
- อ้างอิง ( " ) ในคีย์
- ระยะเวลา ( . ) ในกุญแจ
การโทรนี้สามารถล้มเหลวได้อย่างเงียบๆ หากมีตัวอย่างหลายตัวของปลั๊กอินเดียวกันกำลังอ่านและเขียนข้อมูลอยู่หากปลั๊กอินของคุณคาดว่าจะเขียนการตั้งค่าบ่อยๆ คุณสามารถตรวจสอบได้ว่าข้อมูลถูกเขียนอย่างถูกต้องโดยการโทร Plugin:GetSetting()
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
This code sample demonstrates use of the Plugin:GetSetting() and Plugin:SetSetting() functions. They detect if a plugin is running for the first time by setting a key. If the key is true, it prints a "welcome back" message; otherwise it prints a "first run" message and sets the key to true.
local RAN_BEFORE_KEY = "RunBefore"
local hasRunBefore = plugin:GetSetting(RAN_BEFORE_KEY)
if hasRunBefore then
print("Welcome back!")
else
print("Thanks for installing this plugin!")
plugin:SetSetting(RAN_BEFORE_KEY, true)
end
StartDrag
เริ่มการลาก เริ่มการดำเนินการลากโดยใช้สารบัญของพารามิเตอร์ พารามิเตอร์มีดังนี้:
<th>ประเภท</th><th>ค่าเริ่มต้น</th><th>คําอธิบาย</th></tr></thead><tbody><tr><td><b>ผู้ส่ง</b></td><td>สตริง</td><td><code>""</code></td><td>ระบุที่มาของการดึงแอคชันไปยังเป้าหมายการวาง</td></tr><tr><td><b>ประเภท Mime</b></td><td>สตริง</td><td><code>""</code></td><td>ประเภท <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types">MIME</a> ของ <b>ข้อมูล</b> .</td></tr><tr><td><b>ข้อมูล</b></td><td>สตริง</td><td><code>""</code></td><td>แอ็คชันเช่น สิ่งที่ถูกลาก ควรใช้โดยเป้าหมายการวาง</td></tr><tr><td><b>ไอคอนเมาส์</b></td><td><code>ประเภทข้อมูล.เนื้อหา</code></td><td><code>""</code></td><td>ไอคอนที่จะใช้สำหรับเคอร์เซอร์เมาส์ระหว่างการลาก หากว่างเปล่าจะใช้เคอร์เซอร์เริ่มต้น</td></tr><tr><td><b>ลากไอคอน</b></td><td><code>ประเภทข้อมูล.เนื้อหา</code></td><td><code>""</code></td><td>ภาพที่จะแสดงภายใต้เคอร์เซอร์เมาส์ระหว่างการลาก ซึ่งควรเป็นรายการที่ถูกลาก</td></tr><tr><td><b>จุดร้อน</b></td><td><code>Datatype.Vector2</code></td><td><code>Datatype.Vector2.new(0, 0)</code></td><td>ค่าการเลื่อนพิกเซลจากด้านบนซ้ายที่เคอร์เซอร์ควร "กด" <b>ไอคอนลาก</b></td></tr></tbody>
ชื่อ |
---|
ดูเพิ่ม:
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
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)
Union
รวมส่วนที่กำหนดและ返回การดำเนินการสหภาพที่ได้รับ
พารามิเตอร์
ส่งค่ากลับ
CreateDockWidgetPluginGui
CreateDockWidgetPluginGui สร้างใหม่ DockWidgetPluginGui จาก DockWidgetPluginGuiInfo ที่กำหนดพารามิเตอร์แรก, pluginGuiId , ควรเป็นสตริงที่ไม่ซ้ำกันและสอดคล้องใช้เพื่อบันทึกสถานะของสถานะท่าเรือของวิดเจ็ตและรายละเอียดภายในอื่นๆ
พารามิเตอร์
ตัวระบุที่ไม่ซ้ำและสอดคล้องที่ใช้เพื่อจัดเก็บสถานะท่าเรือของวิดเจ็ตและรายละเอียดภายในอื่นๆ
อธิบาย DockWidgetPluginGui ในการสร้าง (สถานะเริ่มต้น, ขนาดฯลฯ)
ส่งค่ากลับ
ตัวอย่างโค้ด
This code, when ran inside a Plugin, creates a DockWidgetPluginGui with a simple TextButton.
-- Create new 'DockWidgetPluginGuiInfo' object
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float, -- Widget will be initialized in floating panel
true, -- Widget will be initially enabled
false, -- Don't override the previous enabled state
200, -- Default width of the floating window
300, -- Default height of the floating window
150, -- Minimum width of the floating window (optional)
150 -- Minimum height of the floating window (optional)
)
-- Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
local testButton = Instance.new("TextButton")
testButton.BorderSizePixel = 0
testButton.TextSize = 20
testButton.TextColor3 = Color3.new(1, 0.2, 0.4)
testButton.AnchorPoint = Vector2.new(0.5, 0.5)
testButton.Size = UDim2.new(1, 0, 1, 0)
testButton.Position = UDim2.new(0.5, 0, 0.5, 0)
testButton.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton.Text = "Click Me"
testButton.Parent = testWidget
ImportFbxAnimation
ฟังก์ชันนี้จะขอให้ผู้ใช้เปิดไฟล์แอนิเมชัน .fbx ที่สามารถโหลดลงบน rigModel จากนั้นดำเนินการสอดแทรกแอนิเมชันเป็น KeyframeSequence ใน Workspace
พารามิเตอร์
ส่งค่ากลับ
ImportFbxRig
เรียกให้ผู้ใช้เปิดไฟล์ .fbx อัปโหลดส่วนประกอบรายบุคคลของโมเดลเป็นเมช และสร้างชุดตัวละครสำหรับใช้ในการแอนิเมชันซึ่งโหลดลงใน Workspace
พารามิเตอร์
ส่งค่ากลับ
PromptForExistingAssetId
เปิดหน้าต่างใน Roblox Studio ซึ่งจะขอให้ผู้ใช้เลือกสินทรัพย์ตามที่ assetType กำหนดคืนสิ่งที่ assetId ถูกเลือกหรือ -1 หากหน้าต่างถูกปิด
พารามิเตอร์
ส่งค่ากลับ
อีเวนต์
Deactivation
ยิงเมื่อ Plugin ถูกปิดใช้งานสิ่งนี้เกิดขึ้นเมื่อรหัสปลั๊กอินเรียก Plugin:Deactivate() หรือเพราะปลั๊กอินอื่นๆ เรียก Plugin:Activate() ซึ่งทำให้ปลั๊กอินอื่นๆ ทั้งหมดสูญเสียสถานะที่ใช้งาน
ดูเพิ่ม:
- Plugin.Unloading ไฟไหม้ทันทีก่อนที่จะปลดหรือโหลดแอปพลิเคชันอีกครั้งผ่านการถอดออก ปิดใช้งาน หรืออัปเดต
Unloading
อีเวนต์นี้จะเกิดขึ้นทันทีก่อนที่ Plugin จะหยุดทำงานปลั๊กอินจะถูกปิดเมื่อปิดใช้งาน ถอดออก เตรียมอัปเดต หรือเมื่อสถานที่ปิด
มันช่วยให้แพลตฟอร์มสามารถทำความสะอาดหลังจากตัวเองก่อนที่จะหยุดการทำงานของสคริปต์ได้, เช่นเพื่อลบตัวอย่างที่ไม่จำเป็นออกจาก DataModelหากปลั๊กอินไม่ทำความสะอาดอย่างถูกต้อง เอกสารเก่าจะยังคงอยู่เมื่อเกิดขึ้น ผู้ใช้อาจถูกบังคับให้ปิดและเปิดใหม่สถานที่ซึ่งเป็นประสบการณ์ผู้ใช้ที่ไม่ดี
ตัวอย่างที่เกี่ยวข้องกับปลั๊กอินเช่น PluginToolbarButtons , DockWidgetPluginGuis และ PluginGuis จะถูกล้างออกโดยอัตโนมัติเมื่อปลั๊กอินถูกโหลดขึ้น ดังนั้นจึงไม่จำเป็นต้องลบพวกเขา