SerializedProperty and SerializedObject are classes for editing properties on objects in a completely generic way that automatically handles undo, multi-object editing and Prefab overrides.
SerializedProperty is primarily used to read or change the value of a property. It can also iterate through the properties of an object using Next. See Also: SerializedObject class, Editor class.
using UnityEngine; using UnityEditor;
public class MyObject : ScriptableObject { public int myInt = 42; }
public class SerializedPropertyTest : MonoBehaviour { void Start() { MyObject obj = ScriptableObject.CreateInstance<MyObject>(); SerializedObject serializedObject = new UnityEditor.SerializedObject(obj);
SerializedProperty serializedPropertyMyInt = serializedObject.FindProperty("myInt");
Debug.Log("myInt " + serializedPropertyMyInt.intValue); } }
animationCurveValue | 动画曲线属性的值。 |
arrayElementType | 数组属性中元素的类型名称。(只读) |
arraySize | The number of elements in the array. |
boolValue | 布尔值属性的值。 |
boundsIntValue | 带有整数值属性的边界的值。 |
boundsValue | 边界属性的值。 |
colorValue | 颜色属性的值。 |
depth | 属性的嵌套深度。(只读) |
displayName | 属性的友好显示名称。(只读) |
doubleValue | 双精度浮点属性的值。 |
editable | 此属性是否可编辑?(只读) |
enumDisplayNames | 枚举属性的枚举的友好显示名称。 |
enumNames | 枚举属性的枚举的名称。 |
enumValueFlag | Int32 representation of an enum property with Mixed Values. |
enumValueIndex | 枚举属性的枚举索引。 |
exposedReferenceValue | 对场景中另一个对象的引用。系统将在包含 SerializedProperty 的 SerializedObject 的上下文中解析此引用。 |
fixedBufferSize | 固定缓冲区中的元素数量。(只读) |
floatValue | 浮点属性的值。 |
hasChildren | 此属性是否有子属性?(只读) |
hash128Value | The value of a Hash128 property. |
hasMultipleDifferentValues | 此属性是否会因为多对象编辑而代表多个不同的值?(只读) |
hasVisibleChildren | 此属性是否有可见的子属性?(只读) |
intValue | 整数属性的值。 |
isArray | 此属性是否为数组?(只读) |
isDefaultOverride | 允许检查此属性是否为默认重载。预制件实例上的某些属性是默认重载。请参阅 PrefabUtility.IsDefaultOverride 以了解更多信息。 |
isExpanded | 此属性是否在检视面板中展开? |
isFixedBuffer | 此属性是否为固定缓冲区?(只读) |
isInstantiatedPrefab | 属性是否为预制件实例的一部分?(只读) |
longValue | 长整型属性的值。 |
managedReferenceFieldTypename | 与托管引用字段完整类型字符串的值对应的字符串。 |
managedReferenceFullTypename | 与托管引用对象(动态)完整类型字符串的值对应的字符串。 |
managedReferenceId | Id associated with a managed reference. |
managedReferenceValue | The object assigned to a field with SerializeReference attribute. |
minArraySize | The smallest number of elements in the array across all target objects. (Read Only) |
name | 属性的名称。(只读) |
objectReferenceValue | 对象引用属性的值。 |
prefabOverride | 允许检查属性的值是否被重载(即与其所属的预制件不同)。 |
propertyPath | 属性的完整路径。(只读) |
propertyType | 此属性的类型(只读)。 |
quaternionValue | 四元数属性的值。 |
rectIntValue | 带有整数值属性的矩形的值。 |
rectValue | 矩形属性的值。 |
serializedObject | 此属性所属的 SerializedObject(只读)。 |
stringValue | 字符串属性的值。 |
tooltip | 属性的工具提示。(只读) |
type | 属性的类型名称。(只读) |
vector2IntValue | 2D 整数向量属性的值。 |
vector2Value | 2D 向量属性的值。 |
vector3IntValue | 3D 整数向量属性的值。 |
vector3Value | 3D 向量属性的值。 |
vector4Value | 4D 向量属性的值。 |
ClearArray | 从数组中删除所有元素。 |
Copy | 返回 SerializedProperty 迭代器的副本(保留当前状态)。如果您想在继续迭代的同时保存当前属性的引用,则此方法很有用。 |
CountInProperty | 计算此属性的可见子属性的数量,包括属性本身。 |
CountRemaining | 计算剩余可见属性的数量。 |
DeleteArrayElementAtIndex | 删除数组中指定索引处的元素。 |
DeleteCommand | 删除已序列化的属性。 |
DuplicateCommand | 复制已序列化的属性。 |
FindPropertyRelative | 从当前属性的相关路径检索 SerializedProperty。 |
GetArrayElementAtIndex | 返回数组中指定索引处的元素。 |
GetEndProperty | 检索定义此属性起始范围的 SerializedProperty。 |
GetEnumerator | Retrieves an iterator for enumerating over the visible child properties of the current property. If the property is an array it will enumerate over the array elements. |
GetFixedBufferElementAtIndex | 返回固定缓冲区中指定索引处的元素。 |
InsertArrayElementAtIndex | 在数组中的指定索引处插入空元素。 |
MoveArrayElement | 将数组元素从 srcIndex 移到 dstIndex。 |
Next | 移至下一个属性。 |
NextVisible | 移至下一个可见属性。 |
Reset | 移至对象的第一个属性。 |
DataEquals | 比较两个 SerializedProperties 的数据。此方法会忽略路径和 SerializedObjects。 |
EqualContents | 查看包含的序列化属性是否相等。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.