Undo.SetSnapshotTarget 设置快照目标

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

Parameters参数

Description描述

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

通过GUI或Handles所做的修改设置,这样就可以妥善的恢复。

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.

这并不会产生撤销操作(实际的操作,来自应用GUI或Handles并知道何时需要的用户),只是通知GUI或Handles调用什么操作和在哪里应用。

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)

例如当你拖拽操作时,你想保存“临时”的状态,但是你不想注册Undo。(例如当你按下ESC,当移动位置操作)

// 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.
			//当按下鼠标键注册undo
			Undo.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);
}
最后修改:2011年5月18日 Wednesday 14:24

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。