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 | 边界属性的值。 |
| boxedValue | Value of the SerializedProperty, boxed as a System.Object. |
| colorValue | 颜色属性的值。 |
| contentHash | Provides the hash value for the property. (Read Only) |
| depth | 属性的嵌套深度。(只读) |
| displayName | 属性的友好显示名称。(只读) |
| doubleValue | 双精度浮点属性的值。 |
| editable | 此属性是否可编辑?(只读) |
| enumDisplayNames | 枚举属性的枚举的友好显示名称。 |
| enumNames | 枚举属性的枚举的名称。 |
| enumValueFlag | Int32 representation of an enum property with Mixed Values. |
| enumValueIndex | 枚举属性的枚举索引。 |
| exposedReferenceValue | 对场景中另一个对象的引用。系统将在包含 SerializedProperty 的 SerializedObject 的上下文中解析此引用。 |
| fixedBufferSize | 固定缓冲区中的元素数量。(只读) |
| floatValue | 浮点属性的值。 |
| gradientValue | 渐变属性的值。 |
| hasChildren | 此属性是否有子属性?(只读) |
| hash128Value | The value of a Hash128 property. |
| hasMultipleDifferentValues | 此属性是否会因为多对象编辑而代表多个不同的值?(只读) |
| hasVisibleChildren | 此属性是否有可见的子属性?(只读) |
| intValue | 整数属性的值。 |
| isArray | 此属性是否为数组?(只读) |
| isDefaultOverride | 允许检查此属性是否为默认重载。预制件实例上的某些属性是默认重载。请参阅 PrefabUtility.IsDefaultOverride 以了解更多信息。 |
| isExpanded | 此属性是否在检视面板中展开? |
| isFixedBuffer | 此属性是否为固定缓冲区?(只读) |
| isInstantiatedPrefab | 属性是否为预制件实例的一部分?(只读) |
| longValue | Value of an integer property as a long. |
| 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 | 属性的名称。(只读) |
| numericType | Return the precise type for Integer and Floating point properties. (Read Only) |
| objectReferenceValue | 对象引用属性的值。 |
| prefabOverride | 允许检查属性的值是否被重载(即与其所属的预制件不同)。 |
| propertyPath | 属性的完整路径。(只读) |
| propertyType | 此属性的类型(只读)。 |
| quaternionValue | 四元数属性的值。 |
| rectIntValue | 带有整数值属性的矩形的值。 |
| rectValue | 矩形属性的值。 |
| serializedObject | 此属性所属的 SerializedObject(只读)。 |
| stringValue | 字符串属性的值。 |
| tooltip | 属性的工具提示。(只读) |
| type | 属性的类型名称。(只读) |
| uintValue | Value of an integer property as an unsigned int. |
| ulongValue | Value of an integer property as an unsigned long. |
| vector2IntValue | 2D 整数向量属性的值。 |
| vector2Value | 2D 向量属性的值。 |
| vector3IntValue | 3D 整数向量属性的值。 |
| vector3Value | 3D 向量属性的值。 |
| vector4Value | 4D 向量属性的值。 |
| ClearArray | 从数组中删除所有元素。 |
| Copy | Returns a copy of the SerializedProperty iterator in its current state. |
| CountInProperty | 计算此属性的可见子属性的数量,包括属性本身。 |
| CountRemaining | 计算剩余可见属性的数量。 |
| DeleteArrayElementAtIndex | 删除数组中指定索引处的元素。 |
| DeleteCommand | Deletes the array element referenced by the SerializedProperty. |
| DuplicateCommand | Duplicates the array element referenced by the SerializedProperty. |
| 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 | Insert an new element at the specified index in the array. |
| MoveArrayElement | 将数组元素从 srcIndex 移到 dstIndex。 |
| Next | 移至下一个属性。 |
| NextVisible | 移至下一个可见属性。 |
| Reset | 移至对象的第一个属性。 |
| DataEquals | 比较两个 SerializedProperties 的数据。此方法会忽略路径和 SerializedObjects。 |
| EqualContents | 查看包含的序列化属性是否相等。 |