Undo.RegisterSnapshot 注册快照


static function RegisterSnapshot () : void

Description描述

Register the snapshot state made with CreateSnapshot so the user can later undo back to that state.

记录通过CreateSnapshot制作的状态快照,用户可以稍后恢复到那个状态。

参见:SetSnapshotTarget , CreateSnapshotTarget.

// Editor Script Side// Create a position Handle and make the target always look at the position handle.// This is an editor Script, this should go inside the Editor Folder.//创建一个手柄位置,并使目标始终看向手柄位置@CustomEditor (LookAtPoint)class SnapshotTargetEx extends Editor {function OnSceneGUI () {Undo.SetSnapshotTarget(target, "Moved Object Around");target.lookAtPoint =Handles.PositionHandle(target.lookAtPoint, Quaternion.identity);if (GUI.changed)EditorUtility.SetDirty (target);if(Input.GetMouseButtonDown(0)) {// Register the undos when we press the Mouse button.//当按下鼠标键注册undoUndo.CreateSnapshot();Undo.RegisterSnapshot();}}}

And the runtime script that works with this editor Script

// LookAtPoint.js@script ExecuteInEditMode()var lookAtPoint = Vector3.zero;function Update () {transform.LookAt (lookAtPoint);}


,