Version: 2018.2

SerializedObject

class in UnityEditor

Switch to Manual

Description

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

SerializedObject is used in conjunction with SerializedProperty and Editor classes.

See Also: SerializedProperty 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);

UnityEditor.SerializedProperty serializedPropertyMyInt = serializedObject.FindProperty("myInt");

Debug.Log("myInt " + serializedPropertyMyInt.intValue); } }

Variables

contextThe context used to store and resolve ExposedReference types. This is set by the SerializedObject constructor.
isEditingMultipleObjectsDoes the serialized object represents multiple objects due to multi-object editing? (Read Only)
maxArraySizeForMultiEditingDefines the maximum size beyond which arrays cannot be edited when multiple objects are selected.
targetObjectThe inspected object (Read Only).
targetObjectsThe inspected objects (Read Only).

Constructors

SerializedObjectCreate SerializedObject for inspected object.

Public Functions

ApplyModifiedPropertiesApply property modifications.
ApplyModifiedPropertiesWithoutUndoApplies property modifications without registering an undo operation.
CopyFromSerializedPropertyCopies a value from a SerializedProperty to the corresponding serialized property on the serialized object.
CopyFromSerializedPropertyIfDifferentCopies a changed value from a SerializedProperty to the corresponding serialized property on the serialized object.
FindPropertyFind serialized property by name.
GetIteratorGet the first serialized property.
SetIsDifferentCacheDirtyUpdate hasMultipleDifferentValues cache on the next /Update()/ call.
UpdateUpdate serialized object's representation.
UpdateIfRequiredOrScriptUpdate serialized object's representation, only if the object has been modified since the last call to Update or if it is a script.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961