ChangeHistoryService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務

插件開發者 必須 使用 ChangeHistoryService 告訴 Studio 如何撤消和重做他們的插件對體驗所做的變更記錄。在進行變更之前,插件會呼叫 ChangeHistoryService:TryBeginRecording() ,記住它指派的標識符,然後進行變更後,插件會呼叫 ChangeHistoryService:FinishRecording() 來完成記錄。

插件也可以透過 ChangeHistoryService:Undo()ChangeHistoryService:Redo() 程式式地呼叫撤消或重做。

ChangeHistoryService 在運行時不啟用,因此在執行中呼叫其方法沒有效果。

概要

方法

  • FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):()
    外掛程式安全性

    通知工作室已識別的錄音結束,並將最後一步操作完成錄音。

  • 外掛程式安全性

    返回是否有可以撤消的行動,如果有,則返回最後一個。

  • 外掛程式安全性

    返回是否有可以撤消的行動,如果有,則返回最後一個。

  • 外掛程式安全性
  • Redo():()
    外掛程式安全性

    執行被取消的最後一個行動。

  • 外掛程式安全性

    清除歷史記錄,導致所有撤消/重做路點被移除。

  • SetEnabled(state : boolean):()
    外掛程式安全性

    設置是否啟用變更歷史服務。

  • SetWaypoint(name : string):()
    外掛程式安全性

    設置一個新的路點,可用作撤消或重做點。

  • TryBeginRecording(name : string,displayName : string?):string?
    外掛程式安全性

    開始記錄對數據模型進行的更改變更到記錄中。

  • Undo():()
    外掛程式安全性

    撤消最後一次執行的行動,其中有一個路徑點存在。

活動

屬性

方法

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 中的使用者呼叫的行動必須 在完成其對體驗的變更後呼叫 SetWaypoint()之後。在 之前呼叫它可能會清理另一個失敗設置路徑點的插件,但這是一個很差的理由來為自己的外掛程式正當化這種使用。

參數

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