Version: 2022.3

Undo

class in UnityEditor

切换到手册

描述

让您可以针对要执行更改的特定对象注册撤销操作。

撤销系统可以在撤销堆栈中存储增量更改。

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");

静态变量

isProcessingReturns true if the editor is currently processing undo or redo operations, false otherwise.
postprocessModifications每当创建一组新的属性修改时,将触发此回调。
undoRedoEventCallback that is triggered after any undo or redo event.
undoRedoPerformed执行撤销或重做后触发的回调。
willFlushUndoRecord在撤销系统执行刷新之前调用。

静态函数

AddComponent向游戏对象添加组件并针对这一操作注册撤销操作。
ClearAll分别从撤销堆栈和重做堆栈中删除所有撤销和重做操作。
ClearUndo从撤销堆栈中删除使用 Undo.RegisterCompleteObjectUndo 注册的标识符对象的所有撤销操作。
CollapseUndoOperations将组索引之下的所有撤销操作折叠到一个步骤中。
DestroyObjectImmediate销毁对象并记录撤销操作,以便能够重新创建该对象。
FlushUndoRecordObjectsEnsure 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.
GetCurrentGroupUnity 根据当前的组索引自动对撤销操作进行分组。
GetCurrentGroupName获取将在 UI 中显示的当前撤销组的名称。
IncrementCurrentGroupUnity 根据当前的组索引自动对撤销操作进行分组。
MoveGameObjectToScene将游戏对象从当前场景移动到新场景中。 要求游戏对象必须位于当前场景的根目录下。
PerformRedo执行重做操作。
PerformUndo执行撤销操作。
RecordObject记录执行 RecordObject 函数之后对对象所做的任何更改。
RecordObjects将多个可撤销对象记录到单个调用中。这与多次调用 Undo.RecordObject 的效果相同。
RegisterChildrenOrderUndoStores a copy of the order of the object's children on the undo stack.
RegisterCompleteObjectUndo将对象状态存储在撤销堆栈上。
RegisterCreatedObjectUndoRegisters an undo operation to undo the creation of an object.
RegisterFullObjectHierarchyUndo将某个层级视图中所有对象的状态复制到撤销堆栈上。
RegisterImporterUndoCopies the state of the importer for the given asset path.
RevertAllDownToGroup执行组索引之下的所有撤销操作,但在过程中不会存储重做操作。
RevertAllInCurrentGroup执行最后一次撤销操作,但不记录重做操作。
SetCurrentGroupName设置当前撤销组的名称。
SetTransformParent将变换组件的父项设置为新的父项,并记录撤销操作。

委托

PostprocessModifications postprocessModifications 的委托。
UndoRedoCallback undoRedoPerformed 的委托。
UndoRedoEventCallbackDelegate used for undoRedoEvent.
WillFlushUndoRecord willFlushUndoRecord 的委托。