SerializedProperty 序列化属性

SerializedProperty and SerializedObject are classes for editing properties on objects in a completely generic way that automatically handles undo and styling UI for prefabs.

SerializedProperty和SerializedObject类用于对象编辑器属性,是完全通用的方法,自动处理撤销和为预设的UI样式。

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.
注意:这是一个编辑器类,如果想使用它你需要把它放到工程目录下的Assets/Editor文件夹下。编辑器类在UnityEditor命名空间下。所以当使用C#脚本时,你需要在脚本前面加上 "using UnityEditor"引用。

SerializedProperty is used in conjunction with SerializedObject and Editor classes.

SerializedProperty与SerializedObjectEditor类配合使用。

// C# example: A custom Inspector for Transform components.
//自定义Transform组件的检视面板
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Transform))]
public class TransformInspector : Editor {

	SerializedObject m_Object;
	SerializedProperty m_Property;

	void OnEnable () {
		m_Object = new SerializedObject (target);
		m_Property = m_Object.FindProperty ("m_LocalPosition.x");
	}

	void OnInspectorGUI () {
		// Grab the latest data from the object
		//从对象抓取的最新数据
		m_Object.Update ();

		// Editor UI for the property
		//属性的编辑器界面
		EditorGUILayout.PropertyField (m_Property);

		// Apply the property, handle undo
		//应用属性,撤销
		m_Object.ApplyModifiedProperties ();
		}
}

Variables变量

Functions函数

Class Functions类函数

最后修改:2011年10月6日 Thursday 14:50

本脚本参考基于Unity 3.4.1f5

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