Undo 撤销

Lets you register undo operations on specific objects you are about to perform changes on.

让你在特定物体上注册撤销操作,以便你以后执行这个操作。

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.
注意:这是一个编辑器类,如果想使用它你需要把它放到工程目录下的Assets/Editor文件夹下。编辑器类在UnityEditor命名空间下。所以当使用C#脚本时,你需要在脚本前面加上 "using UnityEditor"引用。

The undo system in Unity works by saving the state of one or more objects before performing a change on those objects. It is similar to taking a backup. To undo the change later, the saved state is restored. Since this reverts the objects to the state they had before performing the change, it will be as if the change never happened.

撤销功能,是通过事先对一个或者多个对象状态的保存来实现的,这更像是一个备份。在稍后执行撤销时,备份被恢复,好像从未发生过任何事情。

For instant changes to one or more objects, simply call functions RegisterUndo or RegisterSceneUndo before performing the change that it should be possible to undo.

瞬间撤销一个或多个物体,只需调用函数RegisterUndo 或者 RegisterSceneUndo.

This is all that needs to be done. Unity will automatically handle Undo and Redo for you after that. PerformUndo and PerformRedo should normally not be used unless you want to create your own user interface to the undo system in addition to the user interface Unity already provides.

这就是需要做的全部。Unity会自动处理撤销和重做。PerformUndo和PerformRedo通常不使用,除非你想建立自己的用户界面实现撤销系统。

Using RegisterUndo is most efficient for actions that change one or more objects. RegisterSceneUndo is slower and requires more memory, but it can be used in all cases, and is required for actions that create or destroy objects.

改变一个或多个对象,使用RegisterUndo最有效。RegisterSceneUndo比较缓慢,需要占用更多的内存,但它可以用在所有的情况下。

Certain operations, such as dragging, consist of many small incremental changes. Typically it is not desired to create an undo step for each of these small changes. For example, if the user performs an undo after a dragging operation, it is expected that the object is reverted back to the state it had before the dragging started. The functions SetSnapshotTarget, CreateSnapshot, and RegisterSnapshot are available to handle cases like this.

某些特定的操作,例如拖动,由许多连续变化组成。典型的做法不是想要恢复每一个小的变动。例如,如果用户执行撤销操作,目的是回到拖放开始。SetSnapshotTarget,CreateSnapshot和RegisterSnapshot能够处理这样的情况。

Class Functions类函数

Page last updated: 2011-5-18