插件開發人員 必須使用 Class.ChangeHistoryService 告訴 Studio 如何撤消和重做插件對體驗的變更,這是通過錄像來實現的。在變更之前,插件會呼叫 ChangeHistoryService ,記住它所分配的識別器,然後在變更後,插
插件也可以程式化地邀請撤消或重做通過 ChangeHistoryService:Undo() 或 ChangeHistoryService:Redo()。
ChangeHistoryService 在執行階段時不啟用,因此呼叫它的方法在運行中沒有效果。
概要
方法
- FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):()
通知 Studio ,讓 Studio 知道已完成識別的錄音,並且完成最終操作。
返回可以還原的動作是否存在,並且如果存在,則返回最後一個。
返回可以還原的行動是否存在,並且如果存在,則會返回最後一個。
執行上一個被撤消的動作。
清除歷史,導致所有取消/重做方向點被移除。
設定是否啟用變更歷史服務。
設定一個新的方位點,可以用作還原或重做點。
開始記錄資料模型所做的變更。
還原上一個已執行的行動,其中有一個方向點。
活動
- OnRecordingFinished(name : string,displayName : string?,identifier : string?,operationn : Enum.FinishRecordingOperation,finalOptions : Dictionary?):RBXScriptSignal
發射時發生使用者完成操動作。 參數來自 TryBeginRecording() 和 FinishRecording() 。
發射時間發生錯動作。參數來自 TryBeginRecording() 。
發生時,使用者還原了撤消指令。Waypoint 描述了重做的類型行動。
發射時間發生在用戶在工作室執行動作時。發射點描述未執行的動作類型。
屬性
方法
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)
Redo
執行上一個被撤消的動作。
返回
ResetWaypoints
清除歷史,導致所有取消/重做方向點被移除。
返回
SetEnabled
設定是否啟用變更歷史服務。 當設定為"關閉"時,取消/重做列表將清除,並且不會重新填充。 當設定為"啟用"時,原始列表將不會恢復,但是更多操作將附加到列表上一次
參數
返回
SetWaypoint
此方法將在 Class.ChangeHistoryService:TryBeginRecording()|TryBeginRecording() 的儲存後被TryBeginRecording()。
ChangeHistoryService 跟蹤插件歷史為一個屬性變更的流程。 SetWaypoint() 創建一個切割在那個流程的屬性變更,讓撤消和重做操作知道要停止。
按照規則,Studio 的使用者召喚的操作必須呼叫 Class.ChangeHistoryService:SetWaypoint()|SetWaypoint() 後才能完成對體驗的變更。在完成其變更套外掛程式後,呼叫它 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
參數
行動的名稱適合記錄和編程目的。
顯示給用戶的動作名稱。
儲存的識別器。
Class.ChangeHistoryService.FinishOperation()|FinishOperation() 的可選表。