特定のオブジェクトに対する変更点を Undo クラスによってもとに戻すことができます。
Undo システムは最後に行われた変更を Undo スタックに保存します。
Undo operations automatically combine together based on events. For example, mouse down events split undo groups. Grouped undo operations appear and work as a single undo. To control grouping manually, use Undo.IncrementCurrentGroup.
By default, the name shown in the UI is selected from the actions from the group using a hardcoded ordering of the different kinds of actions. To manually set the name, use Undo.SetCurrentGroupName.
Undo operations store either per property or per object state. They scale well with any Scene size.
The most important operations are outlined below:
Modify a single property:
Undo.RecordObject (myGameObject.transform, "Zero Transform Position");
myGameObject.transform.position = Vector3.zero;
Add a component:
Undo.AddComponent<Rigidbody>(myGameObject);
Create a new GameObject:
var go = new GameObject();
Undo.RegisterCreatedObjectUndo (go, "Created go");
Destroy a GameObject or component:
Undo.DestroyObjectImmediate (myGameObject);
Change transform parenting:
Undo.SetTransformParent (myGameObject.transform, newTransformParent, "Set new parent");
isProcessing | Returns true if the editor is currently processing undo or redo operations, false otherwise. |
postprocessModifications | Callback that is triggered whenever a new set of property modifications is created. |
undoRedoEvent | Callback that is triggered after any undo or redo event. |
undoRedoPerformed | Callback that is triggered after an undo or a redo was executed. |
willFlushUndoRecord | Undo システムがフラッシュを行う前に実行されます。 |
AddComponent | ゲームオブジェクトにコンポーネントをアタッチし、その操作の Undo を登録します。 |
ClearAll | Removes all undo and redo operations from respectively the undo and redo stacks. |
ClearUndo | Undo.RegisterCompleteObjectUndo を使って登録した identifier オブジェクトへの Undo 操作をすべて、Undo スタックから削除します。 |
CollapseUndoOperations | すべての Undo 操作を 1 つのステップにまとめます。 |
DestroyObjectImmediate | オブジェクトを破棄し、Undo 操作によって復元できるように記録します。 |
FlushUndoRecordObjects | Ensure objects recorded using RecordObject or RecordObjects are registered as an undoable action. In most cases there is no reason to invoke FlushUndoRecordObjects since it's automatically done right after mouse-up and certain other events that conventionally marks the end of an action. |
GetCurrentGroup | Unity が自動的に Undo 操作をグループ化したもので現在のグループインデックスを取得します |
GetCurrentGroupName | 現在の Undo グループの UI に表示される名前を取得します。 |
IncrementCurrentGroup | Unity が自動的に Undo 操作をグループ化したもので現在のグループインデックスを取得します |
MoveGameObjectToScene | Move a GameObject from its current Scene to a new Scene. It is required that the GameObject is at the root of its current Scene. |
PerformRedo | Redo 操作を行います。 |
PerformUndo | Undo 操作を行います。 |
RecordObject | RecordObject が呼び出された後の変更点を記録します |
RecordObjects | 1 回の呼び出しで複数の Undo 可能なオブジェクトを記録します。これは複数回 Undo.RecordObject を呼び出すのと同じです。 |
RegisterChildrenOrderUndo | Stores a copy of the order of the object's children on the undo stack. |
RegisterCompleteObjectUndo | Undo スタック上のオブジェクトの状態の複製を保存します。 |
RegisterCreatedObjectUndo | Registers an undo operation to undo the creation of an object. |
RegisterFullObjectHierarchyUndo | オブジェクトのヒエラルキーの状態を Undo スタック上にコピーします。 |
RegisterImporterUndo | Copies the state of the importer for the given asset path. |
RevertAllDownToGroup | 処理中の Redo 操作を保存せずに、グループインデックスまでのすべての Undo 操作を行います。 |
RevertAllInCurrentGroup | Undo 操作は実行されますが Redo 操作は行うことはできません |
SetCurrentGroupName | 現在の Undo グループに名前をつける。 |
SetSiblingIndex | Sets the sibling index of transform and records an undo operation. |
SetTransformParent | 新しく Transform の親を設定し Undo 操作を記録します |
PostprocessModifications | Delegate used for postprocessModifications. |
UndoRedoCallback | undoRedoPerformed に使用されるデリゲート |
UndoRedoEventCallback | Delegate used for undoRedoEvent. |
WillFlushUndoRecord | willFlushUndoRecord に使用されるデリゲート |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.