SerializedProperty 序列化属性

57 篇文章 1 订阅

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 ();
		}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值