Undo.CreateSnapshot 创建快照

static function CreateSnapshot () : void

Description描述

Save the current state of all objects set with SetSnapshotTarget to internal snapshot.

保存对象当前的状态快照,这些对象是通过SetSnapshotTarget设置的。

参见:SetSnapshotTarget , RegisterSnapshotTarget.

// 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:36

本脚本参考基于Unity 3.4.1f5

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