Odin扩展序列化
参考 https://odininspector.com/tutorials/serialize-anything/odin-serializer-quick-start
定义序列化类
Odin 序列化是在unity内置序列化的基础上进行扩展,而不是取代
本质上是实现了 ISerializationCallbackReceiver 接口,在 unity 序列化之后执行 Odin 序列化进行补充
-
从这些类派生的类,会自动执行 Odin 序列化:
- SerializedBehaviour
- SerializedComponent
- SerializedMonoBehaviour
- SerializedNetworkBehaviour
- SerializedScriptableObject
- SerializedStateMachineBehaviour
- SerializedUnityObject
-
无法从上面类派生的,可以这样
- 如果你的类从 ScriptableObject 派生
[ShowOdinSerializedPropertiesInInspector] public class CustomSerializedScriptableObject : ScriptableObject, ISerializationCallbackReceiver { [SerializeField, HideInInspector] private SerializationData serializationData; void ISerializationCallbackReceiver.OnAfterDeserialize() { UnitySerializationUtility.DeserializeUnityObject(this, ref this.serializationData); } void ISerializationCallbackReceiver.OnBeforeSerialize() { UnitySerializationUtility.SerializeUnityObject(this
- 如果你的类从 ScriptableObject 派生