ChangeHistoryService
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
Les développeurs de plugins doivent utiliser ChangeHistoryService pour dire à Studio comment annuler et restaurer les modifications que leurs plugins apportent aux expériences en les enregistrant.Avant de faire des modifications, un plugin appelle ChangeHistoryService:TryBeginRecording(), en se souvenant de l'identifiant qu'il attribue, puis après avoir apporté des modifications, le plugin appelle ChangeHistoryService:FinishRecording() pour terminer l'enregistrement.
Les plugins peuvent également invoquer un annuler ou restaurer de manière programmatique via ChangeHistoryService:Undo() ou ChangeHistoryService:Redo() .
ChangeHistoryService n'est pas activé au moment de l'exécution, donc l'appel de ses méthodes dans une expérience en cours n'a aucun effet.
Résumé
Méthodes
- FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):()
Communique au studio que l'enregistrement identifié est terminé et de prendre la dernière opération pour terminer l'enregistrement.
Renvoie si des actions peuvent être annulées, et, s'il y en a, renvoie la dernière d'entre elles.
Renvoie si des actions peuvent être annulées, et, s'il y en a, renvoie la dernière d'entre elles.
Exécute la dernière action qui a été annulée.
Efface l'histoire, ce qui fait en sorte que tous les points de retour/retour sont supprimés.
Définit si le service historique des modifications est activé ou non.
Définit un nouveau point de passage qui peut être utilisé comme point d'annulation ou de répétition.
Commence à suivre les modifications apportées au modèle de données dans une enregistrement.
Annule la dernière action effectuée, pour laquelle il existe un point de passage.
Événements
- OnRecordingFinished(name : string,displayName : string?,identifier : string?,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):RBXScriptSignal
Tiré lorsque l'utilisateur termine une action. Les paramètres proviennent de TryBeginRecording() et FinishRecording().
Tiré lorsque l'utilisateur commence une action. Les paramètres proviennent de TryBeginRecording() .
Tiré lorsque l'utilisateur annule la commande d'annulation. Waypoint décrit l'action de type qui a été restaurée.
Tiré lorsque l'utilisateur annule une action dans le studio. Waypoint décrit le type d'action qui a été annulé.
Propriétés
Méthodes
FinishRecording
Paramètres
Retours
Échantillons de code
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
Retours
ResetWaypoints
Retours
SetWaypoint
Paramètres
Retours
Échantillons de code
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
Paramètres
Retours
Échantillons de code
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)