让您可以针对要执行更改的特定对象注册撤销操作。
撤销系统可以在撤销堆栈中存储增量更改。
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.
最重要的几项操作如下所述:
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 | 每当创建一组新的属性修改时,将触发此回调。 |
undoRedoEvent | Callback that is triggered after any undo or redo event. |
undoRedoPerformed | 执行撤销或重做后触发的回调。 |
willFlushUndoRecord | 在撤销系统执行刷新之前调用。 |
AddComponent | 向游戏对象添加组件并针对这一操作注册撤销操作。 |
ClearAll | 分别从撤销堆栈和重做堆栈中删除所有撤销和重做操作。 |
ClearUndo | 从撤销堆栈中删除使用 Undo.RegisterCompleteObjectUndo 注册的标识符对象的所有撤销操作。 |
CollapseUndoOperations | 将组索引之下的所有撤销操作折叠到一个步骤中。 |
DestroyObjectImmediate | 销毁对象并记录撤销操作,以便能够重新创建该对象。 |
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 根据当前的组索引自动对撤销操作进行分组。 |
GetCurrentGroupName | 获取将在 UI 中显示的当前撤销组的名称。 |
IncrementCurrentGroup | Unity 根据当前的组索引自动对撤销操作进行分组。 |
MoveGameObjectToScene | 将游戏对象从当前场景移动到新场景中。 要求游戏对象必须位于当前场景的根目录下。 |
PerformRedo | 执行重做操作。 |
PerformUndo | 执行撤销操作。 |
RecordObject | 记录执行 RecordObject 函数之后对对象所做的任何更改。 |
RecordObjects | 将多个可撤销对象记录到单个调用中。这与多次调用 Undo.RecordObject 的效果相同。 |
RegisterChildrenOrderUndo | Stores a copy of the order of the object's children on the undo stack. |
RegisterCompleteObjectUndo | 将对象状态存储在撤销堆栈上。 |
RegisterCreatedObjectUndo | Registers an undo operation to undo the creation of an object. |
RegisterFullObjectHierarchyUndo | 将某个层级视图中所有对象的状态复制到撤销堆栈上。 |
RegisterImporterUndo | Copies the state of the importer for the given asset path. |
RevertAllDownToGroup | 执行组索引之下的所有撤销操作,但在过程中不会存储重做操作。 |
RevertAllInCurrentGroup | 执行最后一次撤销操作,但不记录重做操作。 |
SetCurrentGroupName | 设置当前撤销组的名称。 |
SetSiblingIndex | Sets the sibling index of transform and records an undo operation. |
SetTransformParent | 将变换组件的父项设置为新的父项,并记录撤销操作。 |
PostprocessModifications | postprocessModifications 的委托。 |
UndoRedoCallback | undoRedoPerformed 的委托。 |
UndoRedoEventCallback | Delegate used for undoRedoEvent. |
WillFlushUndoRecord | willFlushUndoRecord 的委托。 |