Undo

class in UnityEditor

Switch to Manual

Description

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

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

系统会根据事件自动将多个撤销操作组合在一起,例如,根据鼠标按下事件拆分撤销组。分组后的撤销操作将作为单个撤销操作出现和使用。要手动控制分组方法,请使用 Undo.IncrementCurrentGroup

默认情况下,系统将按照不同类型操作的硬编码顺序,从属于该组的各项操作中选择 UI 中显示的名称。要手动设置名称,请使用 Undo.SetCurrentGroupName

Undo operations store either per property or per object state. This way they scale well with any Scene size.

The most important operations are outlined below:

Modifying a single property:
Undo.RecordObject (myGameObject.transform, "Zero Transform Position");
myGameObject.transform.position = Vector3.zero;

Adding a component:
Undo.AddComponent<RigidBody>(myGameObject);

Creating a new game object:
var go = new GameObject();
Undo.RegisterCreatedObjectUndo (go, "Created go");

Destroying a game object or component:
Undo.DestroyObjectImmediate (myGameObject);

Changing transform parenting:
Undo.SetTransformParent (myGameObject.transform, newTransformParent, "Set new parent");

Static Variables

undoRedoPerformed执行撤销或重做后触发的回调。
willFlushUndoRecord在撤销系统执行刷新之前调用。

Static Functions

AddComponent向游戏对象添加组件并针对这一操作注册撤销操作。
ClearAll分别从撤销堆栈和重做堆栈中删除所有撤销和重做操作。
ClearUndo从撤销堆栈中删除使用 Undo.RegisterCompleteObjectUndo 注册的标识符对象的所有撤销操作。
CollapseUndoOperations将组索引之下的所有撤销操作折叠到一个步骤中。
DestroyObjectImmediate销毁对象并记录撤销操作,以便能够重新创建该对象。
FlushUndoRecordObjects确保使用 RecordObject 或 ::ref:RecordObjects 记录的对象被注册为可撤销的操作。在大多数情况下,不需要调用 FlushUndoRecordObjects,因为在释放按下的鼠标和通常标志着操作结束的某些其他事件之后,这一操作会自动完成。
GetCurrentGroupUnity 根据当前的组索引自动对撤销操作进行分组。
GetCurrentGroupName获取将在 UI 中显示的当前撤销组的名称。
IncrementCurrentGroupUnity 根据当前的组索引自动对撤销操作进行分组。
MoveGameObjectToSceneMove 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执行重做操作。
PerformUndo执行撤销操作。
RecordObject记录执行 RecordObject 函数之后对对象所做的任何更改。
RecordObjects将多个可撤销对象记录到单个调用中。这与多次调用 Undo.RecordObject 的效果相同。
RegisterCompleteObjectUndo将对象状态存储在撤销堆栈上。
RegisterCreatedObjectUndo针对新创建的对象注册撤销操作。
RegisterFullObjectHierarchyUndo将某个层级视图中所有对象的状态复制到撤销堆栈上。
RevertAllDownToGroup执行组索引之下的所有撤销操作,但在过程中不会存储重做操作。
RevertAllInCurrentGroup执行最后一次撤销操作,但不记录重做操作。
SetCurrentGroupName设置当前撤销组的名称。
SetTransformParent将变换组件的父项设置为新的父项,并记录撤销操作。

Delegates

UndoRedoCallback undoRedoPerformed 的委托。
WillFlushUndoRecord willFlushUndoRecord 的委托。