ChangeHistoryService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
นักพัฒนาปลั๊กอิน ต้องใช้ เพื่อบอก Studio วิธียกเลิกและทำซ้ำการเปลี่ยนแปลงที่ปลั๊กอินของพวกเขาทำให้กับประสบการณ์โดยการบันทึกก่อนที่จะทำการเปลี่ยนแปลง, ปลั๊กอินเรียก ChangeHistoryService:TryBeginRecording() จดจำตัวระบุที่มันกำหนด, จากนั้นหลังจากทำการเปลี่ยนแปลง, ปลั๊กอินเรียก ChangeHistoryService:FinishRecording() เพื่อสรุปการบันทึก
ปลั๊กอินยังสามารถเรียกยกเลิกหรือทำซ้ำผ่าน ChangeHistoryService:Undo() หรือ ChangeHistoryService:Redo() ได้โดยอัตโนมัติ
ChangeHistoryService ไม่ได้เปิดใช้งานในเวลาทำงาน ดังนั้นการเรียกวิธีการของมันในประสบการณ์ที่กําลังดําเนินอยู่จึงไม่มีผล
สรุป
วิธีการ
- FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):()
สื่อสารกับสตูดิโอว่าการบันทึกที่ระบุได้สิ้นสุดแล้วและจะดำเนินการเสร็จสิ้นการบันทึกโดยใช้การดำเนินการสุดท้าย
คืนว่ามีการดำเนินการที่สามารถยกเลิกได้หรือไม่ และหากมี จะคืนการดำเนินการล่าสุด
คืนว่ามีการดำเนินการที่สามารถยกเลิกได้หรือไม่ และหากมี จะคืนการดำเนินการล่าสุด
ดําเนินการด้วยการกระทําสุดท้ายที่ถูกยกเลิก
ล้างประวัติทำให้จุดย้อนกลับทั้งหมดถูกลบออก
ตั้งค่าว่า ChangeHistoryService จะเปิดใช้งานหรือไม่
ตั้งจุดเวย์พอยท์ใหม่ซึ่งสามารถใช้เป็นจุดย้อนกลับหรือทำซ้ำได้
เริ่มติดตามการเปลี่ยนแปลงที่ทำต่อโมเดลข้อมูลเป็นการบันทึก
ยกเลิกการกระทำครั้งล่าสุดที่มีเวย์พอยท์อยู่
อีเวนต์
- OnRecordingFinished(name : string,displayName : string?,identifier : string?,operation : 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)
GetCanRedo
คืนว่ามีการดำเนินการที่สามารถยกเลิกได้หรือไม่ และหากมี จะคืนการดำเนินการล่าสุด
ส่งค่ากลับ
GetCanUndo
คืนว่ามีการดำเนินการที่สามารถยกเลิกได้หรือไม่ และหากมี จะคืนการดำเนินการล่าสุด
ส่งค่ากลับ
Redo
ดําเนินการด้วยการกระทําสุดท้ายที่ถูกยกเลิก
ส่งค่ากลับ
ResetWaypoints
ล้างประวัติทำให้จุดย้อนกลับทั้งหมดถูกลบออก
ส่งค่ากลับ
SetEnabled
ตั้งค่าว่า ChangeHistoryService จะเปิดใช้งานหรือไม่เมื่อตั้งค่าเป็น false รายการยกเลิก/ย้อนกลับจะถูกล้างและไม่ถูกเติมใหม่เมื่อตั้งค่าเป็นจริงอีกครั้ง รายการเดิมจะไม่ถูกฟื้นคืน แต่การดำเนินการเพิ่มเติมจะถูกเพิ่มลงในรายการอีกครั้ง
พารามิเตอร์
ส่งค่ากลับ
SetWaypoint
วิธีนี้จะถูกยกเลิกในเร็ว ๆ นี้ เพื่อสนับสนุน แทน
ChangeHistoryService บันทึกประวัติปลั๊กอินเป็นสตรีมของการเปลี่ยนแปลงคุณสมบัติSetWaypoint() สร้างการตัดในสตรีมการเปลี่ยนแปลงคุณสมบัติที่จะทำให้การยกเลิกและการทำซ้ำรู้ว่าจะหยุดที่ไหน
ตามข้อตกลง การดำเนินการที่เรียกโดยผู้ใช้ใน Studio ต้อง โทร หลังจากเสร็จสิ้นชุดของการเปลี่ยนแปลงให้กับประสบการณ์แล้วเรียกมัน ก่อน ชุดของการเปลี่ยนแปลงอาจล้างแอพพลิเคชันที่ไม่ดีที่ไม่สามารถตั้งเวย์พอยท์ได้ ปลั๊กอิน
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
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
ยิงเมื่อผู้ใช้ยกเลิกการดำเนินการในสตูดิโอ เวย์พอยท์อธิบายประเภทการดำเนินการที่ถูกยกเลิก