Version: 2022.2

EditorUtility.CopySerializedManagedFieldsOnly

切换到手册
public static void CopySerializedManagedFieldsOnly (object source, object dest);

参数

source 要从中复制数据的对象。
dest 要将数据复制到的对象。

描述

在不同的托管对象之间复制可序列化的字段。

这类似于 CopySerialized,但您可以将它与任何两个托管对象一起使用,但同一个 Object 子类的两个实例除外。

CopySerializedManagedFieldsOnly copies all fields supported by the Unity serializer. If the destination object is not of the same class as the source object, then the function matches fields by name, or by using the FormerlySerializedAs attribute. The function does not modify any fields on the destination object which are not serializable, or which do not have corresponding fields in the source object.

如果源对象实现 ISerializationCallbackReceiver 接口,则在读取任何数据之前调用其 OnBeforeSerialize 方法。同样,如果目标对象实现 ISerializationCallbackReceiver,则在数据已经复制到其字段之后调用其 OnAfterDeserialize 方法。

CopySerializedManagedFieldsOnly only copies fields defined in managed code. This means that if you attempt to copy engine objects such as Transform or Light, CopySerializedManagedFieldsOnly does not copy any data, since all of their serializable fields are defined in native code.