ChangeHistoryService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ผู้พัฒนาปลั๊กอิน จะต้องใช้ Class.ChangeHistoryService เพื่อบอก Studio วิธีการยกเลิกและทำซ้ำการเปลี่ยนแปลงที่พวกเขาทำให้กับป
ปลั๊กอินอาจเรียกใช้งานได้โปรแกรมมิงผ่าน ChangeHistoryService:Undo() หรือ ChangeHistoryService:Redo() ด้วย
ChangeHistoryService ไม่สามารถใช้ได้ในขณะที่เริ่มต้นได้ ดังนั้นการเรียกวิธีการของมันในประสบการณ์ที่ดำเนินอยู่จะไม่มีผล
สรุป
วิธีการ
- FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):void
สื่อสารกับ Studio ว่าบันทึกที่ระบุไว้เสร็จสิ้นแล้วและจะทำการดำเนินการสุดท้ายเพื่อเสร็จสิ้นการบันทึก
กลับว่ามีการทำซ้ำหรือไม่ และ, ถ้ามี, กลับสุดท้ายของพวกเขา
กลับว่ามีการกระทำที่สามารถยกเลิกได้หรือไม่ และหากมีการกระทำใด ๆ ก็จะกลับคืนสุดท้าย
ดำเนินการที่สุดที่ยกเลิก
ล้างประวัติ ทำให้ทุกจุดมุ่งหมายที่ทำซ้ำ/ทำใหม่ถูกลบออก
ตั้งค่าว่า ChangeHistoryService จะเปิดใช้งานหรือไม่
ตั้งค่าจุดใหม่ที่สามารถใช้เป็นจุดย้อนกลับหรือทำซ้ำ
เริ่มติดตามการเปลี่ยนแปลงของข้อมูลไปยังบันทึก
ยกเลิกการกระทําล่าสุดที่มีวิธีชี้นำ
อีเวนต์
- OnRecordingFinished(name : string,displayName : string?,identifier : string?,operationn : Enum.FinishRecordingOperation,finalOptions : Dictionary?):RBXScriptSignal
แอ็คชันตัวแปรมาจาก TryBeginRecording() และ FinishRecording()
เริ่มต้นด้วยการใช้งานเมื่อผู้ใช้เริ่มการดำเนินการ ตัวแปรมาจาก TryBeginRecording()
ไฟร์เมื่อผู้ใช้ยกเลิกคำสั่งยกเลิก วิธีการจุดเริ่มต้นอธิบายประเภทของการดำเนินการที่ได้รับการทำซ้ำ
ไฟร์เมื่อผู้ใช้ทำการกลับทำการในสตูดิโอ วิธีการจุดไฟร์อธิบายประเภทการกลับทำที่เกิดขึ้น
คุณสมบัติ
วิธีการ
FinishRecording
พารามิเตอร์
ระบุการบันทึกจากการโทรก่อนหน้านี้ไปยัง TryBeginRecording() หากการดำเนินการนี้เป็น Enum.ChangeHistoryService.FinishRecordingOperation.Cancel จะไม่มีการบันทึกนี้ และการบันทึกจะได้รับการกำหนดโด
ระบุการดำเนินการที่จะใช้
ตารางของค่าที่เป็นตัวแปรสำหรับการส่งไปยัง OnFinishRecording
ส่งค่ากลับ
ตัวอย่างโค้ด
To commit an undo/redo record, you need to first call TryBeginRecording() followed by calling FinishRecording().
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Example Plugin")
local button = toolbar:CreateButton("Neon it up", "", "")
button.Click:Connect(function()
local parts = {}
for _, part in pairs(Selection:Get()) do
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
if #parts < 1 then
-- Nothing to do.
return
end
local recording = ChangeHistoryService:TryBeginRecording("Set selection to neon")
if not recording then
-- Handle error here. This indidcates that your plugin began a previous
-- recording and never completed it. You may only have one recording
-- per plugin active at a time.
return
end
for _, part in pairs(parts) do
part.Material = Enum.Material.Neon
end
ChangeHistoryService:FinishRecording(recording, Enum.FinishRecordingOperation.Commit)
end)
GetCanUndo
กลับว่ามีการกระทำที่สามารถยกเลิกได้หรือไม่ และหากมีการกระทำใด ๆ ก็จะกลับคืนสุดท้าย
ส่งค่ากลับ
Redo
ดำเนินการที่สุดที่ยกเลิก
ส่งค่ากลับ
ResetWaypoints
ล้างประวัติ ทำให้ทุกจุดมุ่งหมายที่ทำซ้ำ/ทำใหม่ถูกลบออก
ส่งค่ากลับ
SetEnabled
ตั้งค่าว่า ChangeHistoryService เปิดหรือไม่ เมื่อตั้งค่าเป็น false จะล้างรายการยกเลิก/ทำซ้ำ และไม่สร้างใหม่ เมื่อตั้งค่าเป็น true อีกครั้ง รายการดั้งเดิมจะไม่ถูกคืน แต่การดำเนินการต่อไปจะแนบมาที่รายการอี
พารามิเตอร์
ส่งค่ากลับ
SetWaypoint
วิธีนี้จะถูก แก้ไขในเร็ว ๆ นี้ ในความโปรดปรานของ TryBeginRecording()
ChangeHistoryService ติดตามประวัติของปลั๊กอินในฐานะสตรีมการเปลี่ยนแปลงสมบัติที่เป็นไปได้ SetWaypoint() สร้างการตัดในสตรีมการเปลี่ยนแปลงเหล่านั้นเพื่อให้ und
ตามปกติ, การกระทําที่เรียกโดยผู้ใช้ใน Studio จะต้อง โทร SetWaypoint() หลังจากที่พวกเขาเสร็จสิ้นการเปลี่ย
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
In order for the waypoints to work correctly, you need to set one both before AND after you perform the action that should be able to be undone.
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Example Plugin")
local button = toolbar:CreateButton("Neon it up", "", "")
button.Click:Connect(function()
local parts = {}
for _, part in pairs(Selection:Get()) do
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
if #parts > 0 then
-- Calling SetWaypoint before the work will not cause any issues, however
-- it is redundant, only the call AFTER the work is needed.
--ChangeHistoryService:SetWaypoint("Setting selection to neon")
for _, part in pairs(parts) do
part.Material = Enum.Material.Neon
end
-- Call SetWaypoint AFTER completing the work
ChangeHistoryService:SetWaypoint("Set selection to neon")
else
-- Nothing to do. You do not need to call SetWaypoint in the case where
-- the action did not end up making any changes to the experience.
end
end)
TryBeginRecording
วิธีนี้เริ่มบันทึกเพื่อติดตามการเปลี่ยนแปลงในแบบข้อมูล คุณต้อง ต้อง เรียกมันก่อนที่จะทำการเปลี่ยนแปลงเพื่อหลีกเลี่ยงคำเตือนหรือข้อผิดพลาดในอนาคต
เมื่อการบันทึกเสร็จสิ้นคุณจะโทร FinishRecording() ด้วยตัวระบุการบันทึกที่กลับมาเพื่อเสร็จสิ้นการบันทึกและปรับปรุงการยกเลิก/ทำซ้ำสต็อก
วิธีนี้จะกลับมา nil หากไม่สามารถเริ่มบันทึกได้ บันทึกจะล้มเหลวหากปลั๊กอินมีการบันทึกอยู่แล้วหรือหากผู้ใช้อยู่ในโหมด วิ่ง หรือ เล่น คุณสามารถใช้ IsRecordingInProgress() เพื่อตรวจสอบสถานะการบันทึกของปลั๊กอิน
พารามิเตอร์
ชื่อการดำเนินการที่เหมาะสมสำหรับการบันทึกและการเขียนโค้ด
ชื่อของการกระทําที่จะแสดงให้กับผู้ใช้
ส่งค่ากลับ
ตัวอย่างโค้ด
To commit an undo/redo record, you need to first call TryBeginRecording() followed by calling FinishRecording().
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Example Plugin")
local button = toolbar:CreateButton("Neon it up", "", "")
button.Click:Connect(function()
local parts = {}
for _, part in pairs(Selection:Get()) do
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
if #parts < 1 then
-- Nothing to do.
return
end
local recording = ChangeHistoryService:TryBeginRecording("Set selection to neon")
if not recording then
-- Handle error here. This indidcates that your plugin began a previous
-- recording and never completed it. You may only have one recording
-- per plugin active at a time.
return
end
for _, part in pairs(parts) do
part.Material = Enum.Material.Neon
end
ChangeHistoryService:FinishRecording(recording, Enum.FinishRecordingOperation.Commit)
end)
Undo
ยกเลิกการกระทําล่าสุดที่มีวิธีชี้นำ
ส่งค่ากลับ
อีเวนต์
OnRecordingFinished
พารามิเตอร์
ชื่อการดำเนินการที่เหมาะสมสำหรับการบันทึกและการเขียนโค้ด
ชื่อของการกระทําที่จะแสดงให้กับผู้ใช้
รหัสประจำตัวสำหรับการบันทึก
ตารางที่เปิดใช้งานได้จาก FinishOperation()
OnRecordingStarted
พารามิเตอร์
ชื่อการดำเนินการที่เหมาะสมสำหรับการบันทึกและการเขียนโค้ด
ชื่อของการกระทําที่จะแสดงให้กับผู้ใช้
OnRedo
ไฟร์เมื่อผู้ใช้ยกเลิกคำสั่งยกเลิก วิธีการจุดเริ่มต้นอธิบายประเภทของการดำเนินการที่ได้รับการทำซ้ำ
พารามิเตอร์
OnUndo
ไฟร์เมื่อผู้ใช้ทำการกลับทำการในสตูดิโอ วิธีการจุดไฟร์อธิบายประเภทการกลับทำที่เกิดขึ้น