ChangeHistoryService

사용되지 않는 항목 표시
만들 수 없음
서비스

Plugin developers must use ChangeHistoryService to tell Studio how to undo and redo changes that their plugins make to experiences by recording. Before making changes, a plugin calls ChangeHistoryService:TryBeginRecording(), remembering the identifier it assigns, then after making changes, the Plugin calls ChangeHistoryService:FinishRecording() to complete the recording.

Plugins may also programmatically invoke an undo or redo through ChangeHistoryService:Undo() or ChangeHistoryService:Redo().

ChangeHistoryService is not enabled at runtime, so calling its methods in a running experience has no effect.

요약

메서드

  • FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):void
    플러그인 보안

    Communicates to Studio that the identified recording is finished and to take the final operation to complete the recording.

  • 플러그인 보안

    Returns whether there are actions that can be redone, and, if there are, returns the last of them.

  • 플러그인 보안

    Returns whether there are actions that can be undone, and, if there are, returns the last of them.

  • 플러그인 보안
  • Redo():void
    플러그인 보안

    Executes the last action that was undone.

  • 플러그인 보안

    Clears the history, causing all undo/redo waypoints to be removed.

  • SetEnabled(state : bool):void
    플러그인 보안

    Sets whether or not the ChangeHistoryService is enabled.

  • SetWaypoint(name : string):void
    플러그인 보안

    Sets a new waypoint which can be used as an undo or redo point.

  • TryBeginRecording(name : string,displayName : string?):string?
    플러그인 보안

    Begins tracking changes made to the data model into a recording.

  • Undo():void
    플러그인 보안

    Undos the last action taken, for which there exists a waypoint.

이벤트

속성

메서드

FinishRecording

void
플러그인 보안

매개 변수

identifier: string

Identifies the recording from the previous call to TryBeginRecording(). If the operation is Enum.ChangeHistoryService.FinishRecordingOperation.Cancel, this value is ignored, and the recording is determined by context.

Specifies the operation to take.

finalOptions: Dictionary

Optional table of values to pass to OnFinishRecording.


반환

void

코드 샘플

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

플러그인 보안

Returns whether there are actions that can be redone, and, if there are, returns the last of them.


반환

GetCanUndo

플러그인 보안

Returns whether there are actions that can be undone, and, if there are, returns the last of them.


반환

IsRecordingInProgress

플러그인 보안

매개 변수

identifier: string

반환

Redo

void
플러그인 보안

Executes the last action that was undone.


반환

void

ResetWaypoints

void
플러그인 보안

Clears the history, causing all undo/redo waypoints to be removed.


반환

void

SetEnabled

void
플러그인 보안

Sets whether or not the ChangeHistoryService is enabled. When set to false, the undo/redo list is cleared, and does not repopulate. When set to true again, the original list is not restored, but further operations append to the list once more

매개 변수

state: bool

반환

void

SetWaypoint

void
플러그인 보안

This method will be deprecated soon in favor of TryBeginRecording().

ChangeHistoryService tracks plugin history as a stream of property changes. SetWaypoint() creates a cut in that stream of property changes so that the undo and redo actions know where to stop.

By convention, user-invoked actions in Studio must call SetWaypoint() after completing their set of changes to the experience. Calling it before a set of changes may clean up another misbehaving plugin which failed to set a waypoint, but it's a poor reason to justify such usage in your own plugin.

매개 변수

name: string

반환

void

코드 샘플

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

플러그인 보안

This method begins a recording to track changes to the data model. You must call it prior to making changes to avoid future warnings or errors.

When the recording is completed, you call FinishRecording() with the returned recording identifier to complete the recording and update the undo/redo stack.

This method will return nil if it fails to begin a recording. Recordings fail if the plugin already has a recording in progress, or if the user is in Run or Play mode.

You may use IsRecordingInProgress() to check the recording status of the plugin.

매개 변수

name: string

Name of the action being performed suitable for logging and coding purposes.

displayName: string

Name of the action being performed to display to the user.


반환

코드 샘플

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

void
플러그인 보안

Undos the last action taken, for which there exists a waypoint.


반환

void

이벤트

OnRecordingFinished

플러그인 보안

매개 변수

name: string

Name of the action being performed suitable for logging and coding purposes.

displayName: string

Name of the action being performed to display to the user.

identifier: string

The identifier for the recording.

finalOptions: Dictionary

Optional table from FinishOperation().


OnRecordingStarted

플러그인 보안

매개 변수

name: string

Name of the action being performed suitable for logging and coding purposes.

displayName: string

Name of the action being performed to display to the user.


OnRedo

플러그인 보안

Fired when the user reverses the undo command. Waypoint describes the type action that has been redone.

매개 변수

waypoint: string

OnUndo

플러그인 보안

Fired when the user undoes an action in studio. Waypoint describes the type action that has been undone.

매개 변수

waypoint: string