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.
瞬间撤销一个或多个物体，只需调用函数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.
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.
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.