public static void RecordObject (Object objectToUndo, string name);

Parameters

objectToUndo对要修改对象的引用。
name要在撤消历史记录中显示(即在撤销菜单中可见)的操作的名称。

Description

记录执行 RecordObject 函数之后对对象所做的任何更改。

使用这一函数可以记录几乎所有属性更改。无法使用这一函数记录变换组件的父项、AddComponent 和对象销毁,应该使用专用函数来记录。

Internally this creates a temporary copy of the object's state. At the end of the frame Unity diffs the state and detects what has changed. The changed properties are recorded on the undo stack. If nothing has changed (Binary exact comparison is used for all properties), no undo operations are stored on the stack.

Important: To correctly handle instances where objectToUndo is an instance of a Prefab, PrefabUtility.RecordPrefabInstancePropertyModifications must be called after RecordObject.

下面是一个编辑器脚本的示例,可用于更改特效的半径变量。系统会记录撤销状态,这样您就可以使用撤销系统来恢复更改。

//Name this script "EffectRadiusEditor"
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(EffectRadius))] public class EffectRadiusEditor : Editor { public void OnSceneGUI() { EffectRadius t = (target as EffectRadius);

EditorGUI.BeginChangeCheck(); float areaOfEffect = Handles.RadiusHandle(Quaternion.identity, t.transform.position, t.areaOfEffect); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Changed Area Of Effect"); t.areaOfEffect = areaOfEffect; } } }

Place this script on a GameObject to see the area of effect handle, and change the value using the gizmo in the Scene view.

//Name this script "EffectRadius"
using UnityEngine;
using System.Collections;

public class EffectRadius : MonoBehaviour { public float areaOfEffect = 1; }