public override void WriteWeak(IValueStorage targetObject, object sourceObject) { VerifySerializationSanity(); if (sourceObject != null && !UdonSharpUtils.IsUserJaggedArray(sourceObject.GetType())) { throw new SerializationException($"Cannot convert {targetObject.GetType()} to {typeMetadata.cSharpType}"); } object tarArray = targetObject.Value; ConvertToUdonArrayElement(ref tarArray, sourceObject, typeMetadata.cSharpType); targetObject.Value = tarArray; }
public override void Read(ref T targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { UdonSharpUtils.LogError($"Field for {typeof(T)} does not exist"); return; } if (UsbSerializationContext.CollectDependencies) { if (sourceObject.Value is UnityEngine.Object unityObject && unityObject != null) { UsbSerializationContext.Dependencies.Add(unityObject); } return; } IValueStorage storage = sourceObject as ValueStorage <T>; if (storage == null) { Type storageType = sourceObject.GetType().GetGenericArguments()[0]; if (typeof(T).IsSubclassOf(storageType)) { storage = sourceObject; } else if (targetObject != null && targetObject.GetType().IsAssignableFrom(storageType)) { storage = sourceObject; } else if (targetObject == null && storageType.IsSubclassOf(typeof(T))) { storage = sourceObject; } else { UdonSharpUtils.LogError($"Type {typeof(T)} not compatible with serializer {sourceObject}"); return; } } targetObject = (T)storage.Value; }
public override void Read(ref T targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { Debug.LogError($"Field for {typeof(T)} does not exist"); return; } IValueStorage storage = sourceObject as ValueStorage <T>; if (storage == null) { System.Type storageType = sourceObject.GetType().GetGenericArguments()[0]; if (typeof(T).IsSubclassOf(storageType)) { storage = sourceObject; } else if (targetObject != null && targetObject.GetType().IsAssignableFrom(storageType)) { storage = sourceObject; } else if (targetObject == null && storageType.IsSubclassOf(typeof(T))) { storage = sourceObject; } else { Debug.LogError($"Type {typeof(T)} not compatible with serializer {sourceObject}"); return; } } targetObject = (T)storage.Value; }