Undo.SetSnapshotTarget 设置快照目标

static function SetSnapshotTarget (objectToUndo : Object, name : string) : void
static function SetSnapshotTarget (objectsToUndo : Object[], name : string) : void



Set the objects modified by the GUI or Handles so they can undo properly.


This does not push an undo (the actual GUI or Handles are the ones who know when this is needed), but only informs the GUI or Handles what to call the operation on and where you end up applying it.


This happens for example when you are issuing drag and drop operations and you want to save a "temporary" state but you dont want to register as an Undo action. (For example when you click ESC when moving the position handle)


// 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.

And the runtime script that works with this editor Script

// LookAtPoint.js

@script ExecuteInEditMode()

var lookAtPoint = Vector3.zero;

function Update () {
	transform.LookAt (lookAtPoint);
Page last updated: 2011-5-18