ChangeHistoryService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务

插件开发者 必须 使用 ChangeHistoryService 告诉 Studio 如何撤消和重做插件对体验造成的更改,通过录制。在进行更改之前,插件调用 ChangeHistoryService:TryBeginRecording() ,记住它分配的标识符,然后进行更改后,插件调用 ChangeHistoryService:FinishRecording() 完成录制。

插件也可以通过 ChangeHistoryService:Undo()ChangeHistoryService:Redo() 编程地调用撤消或重做。

ChangeHistoryService 在执行时间时不启用,因此在运行体验中调用其方法无效。

概要

方法

活动

属性

方法

FinishRecording

()
插件安全性

参数

identifier: string

识别从前一次调用到 TryBeginRecording() 的记录。如果操作是 Enum.ChangeHistoryService.FinishRecordingOperation.Cancel,这个值被忽略,记录由上下文决定。

默认值:""

指定要执行的操作。

默认值:""
finalOptions: Dictionary

可选的值表,用于传递到 OnFinishRecording .

默认值:""

返回

()

代码示例

To commit an undo/redo record, you need to first call TryBeginRecording() followed by calling FinishRecording().

ChangeHistoryService:TryBeginRecording

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

插件安全性

返回是否存在可以撤消的操作,如果存在,返回最后一个。


返回

IsRecordingInProgress

插件安全性

参数

identifier: string
默认值:""

返回

Redo

()
插件安全性

执行被撤销的最后一次行动。


返回

()

ResetWaypoints

()
插件安全性

清除历史,导致所有撤消/重做路径点被移除。


返回

()

SetEnabled

()
插件安全性

设置是否启用更改历史服务。当设置为 false 时,撤消/重做列表将清除,不会重新填充。当设置为真时再次设置为真时,原始列表不会恢复,但进一步操作将再次添加到列表

参数

state: boolean
默认值:""

返回

()

SetWaypoint

()
插件安全性

该方法将很快被 淘汰 ,转而使用 TryBeginRecording()

ChangeHistoryService 跟踪插件历史记录作为一串属性更改的流。SetWaypoint() 创建在那个属性更改流中的切割,以便撤消和重做操作知道停止在哪里。

根据惯例,Studio 中的用户触发的行动必须调用后完成其对体验的更改集。在 之前调用它可能会清理另一个失败的插件,没有设置路径点的,但这是一个很差的理由为自己的插件正当化这种使用。

参数

name: string
默认值:""

返回

()

代码示例

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.

ChangeHistoryService:SetWaypoint

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() 来检查插件的录制状态。

参数

name: string

执行的动作名称适合用于记录和编码目的。

默认值:""
displayName: string

执行给用户显示的行动名称。

默认值:""

返回

代码示例

To commit an undo/redo record, you need to first call TryBeginRecording() followed by calling FinishRecording().

ChangeHistoryService:TryBeginRecording

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

插件安全性

参数

name: string

执行的动作名称适合用于记录和编码目的。

displayName: string

执行给用户显示的行动名称。

identifier: string

记录的标识符。

finalOptions: Dictionary

可选表从 FinishOperation()


OnRecordingStarted

插件安全性

参数

name: string

执行的动作名称适合用于记录和编码目的。

displayName: string

执行给用户显示的行动名称。


OnRedo

插件安全性

当用户反向撤消命令时发射。路径描述了已被撤消的类型操作。

参数

waypoint: string

OnUndo

插件安全性

当用户在工作室中撤消行动时发射。路径描述已撤消的类型行动。

参数

waypoint: string