主要是使用unity里的Undo的API。
1.Undo.RegisterCreatedObjectUndo //撤销创建
[MenuItem("Example/Create Cube")]
static void CreateCube()
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
Undo.RegisterCreatedObjectUndo(cube, "Create Cube");
}
2.Undo.DestroyObjectImmediate //撤销对象销毁
[MenuItem("Example/UndoDestory")]
static void UndoDestory()
{
GameObject player = Selection.activeGameObject;
if (player)
{
// Store the states of the player object.
Undo.DestroyObjectImmediate(player);
Object.DestroyImmediate(player);
}
}
3 Undo.RegisterCompleteObjectUndo //撤销Object的状态
能撤销object的各种公共字段的修改。
除了AddComponent,改变父子关系和销毁。
[MenuItem("Example/RegisterCompleteObjectUndo")]
static void Example()
{