插件开发者 必须使用 Class.ChangeHistoryService 告诉 Studio 如何撤销和重做插件对体验的更改,通过录制。在更改之前,插件调用 Class.ChangeHistoryService:TryBeginRecording(),记住它分配的标识符,然后在更改之后,插件调用 Class.ChangeHistoryService:FinishRecording() 来完
插件还可以通过 ChangeHistoryService:Undo() 或 ChangeHistoryService:Redo() 来程序化撤销或重做。
ChangeHistoryService 在执行时间时不启用,所以在运行体验中调用它的方法无效。
概要
方法
- FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):void
向 Studio 通知已完成识别的录音,并完成最终操作以完成录音。
返回是否有可以撤销的操作,以及, 如果有, 返回最后一个.
返回是否有可撤销的操作,如果有,还会返回上一步。
执行上一个已撤消的操作。
清除历史,导致所有撤销/重做方向点被移除。
设置是否启用更改历史服务。
设置一个新的 Waypoint,可以用作撤销或重做点。
将数据模型上的更改变成录音。
撤销最后一个已执行的操作,为其存在一个方向点。
活动
- 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 的用户邀请操作在 必须 调用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
参数
适合日志和代码目的的操作名称。
显示给用户的操作名称。
用于记录的标识。