コード例 #1
0
        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;
        }
コード例 #2
0
        private void ConvertToCSharpArrayElement(ref object targetElement, object elementValue, Type cSharpType)
        {
            if (elementValue == null)
            {
                targetElement = null;
                return;
            }

            if (UdonSharpUtils.IsUserJaggedArray(cSharpType))
            {
                Array targetArray = (Array)targetElement;
                Array sourceArray = (Array)elementValue;

                if (!UsbSerializationContext.CollectDependencies)
                {
                    if (targetArray == null || targetArray.Length != sourceArray.Length)
                    {
                        targetElement = targetArray = (Array)Activator.CreateInstance(cSharpType, sourceArray.Length);
                    }
                }

                for (int i = 0; i < sourceArray.Length; ++i)
                {
                    object elementVal = targetArray.GetValue(i);
                    ConvertToCSharpArrayElement(ref elementVal, sourceArray.GetValue(i), cSharpType.GetElementType());

                    if (!UsbSerializationContext.CollectDependencies)
                    {
                        targetArray.SetValue(elementVal, i);
                    }
                }
            }
            else if (cSharpType.IsArray)
            {
                IValueStorage innerArrayValueStorage = GetInnerValueStorage();
                innerArrayValueStorage.Value = elementValue;
                rootArraySerializer.ReadWeak(ref targetElement, innerArrayValueStorage);

                innerValueStorages.Push(innerArrayValueStorage);
            }
            else
            {
                throw new Exception("Jagged array serializer requires a root array serializer");
            }
        }
コード例 #3
0
        void ConvertToUdonArrayElement(ref object targetElement, object elementValue, System.Type cSharpType)
        {
            if (elementValue == null)
            {
                targetElement = null;
                return;
            }

            if (UdonSharpUtils.IsUserJaggedArray(cSharpType))
            {
                Array targetArray = (Array)targetElement;
                Array sourceArray = (Array)elementValue;

                if (targetArray == null || targetArray.Length != sourceArray.Length)
                {
                    targetElement = targetArray = (Array)Activator.CreateInstance(UdonSharpUtils.UserTypeToUdonType(cSharpType), new object[] { sourceArray.Length });
                }

                for (int i = 0; i < sourceArray.Length; ++i)
                {
                    object elementVal = targetArray.GetValue(i);
                    ConvertToUdonArrayElement(ref elementVal, sourceArray.GetValue(i), cSharpType.GetElementType());
                    targetArray.SetValue(elementVal, i);
                }
            }
            else if (cSharpType.IsArray)
            {
                IValueStorage innerArrayValueStorage = GetInnerValueStorage();

                innerArrayValueStorage.Value = targetElement;
                rootArraySerializer.WriteWeak(innerArrayValueStorage, elementValue);
                targetElement = innerArrayValueStorage.Value;

                innerValueStorages.Push(innerArrayValueStorage);
            }
            else
            {
                throw new Exception("Jagged array serializer requires a root array serializer");
            }
        }