コード例 #1
0
        public TypeSymbol GetUdonTypeSymbol(ITypeSymbol type, AbstractPhaseContext context)
        {
            if (!TypeSymbol.TryGetSystemType(type, out var systemType))
            {
                throw new InvalidOperationException("foundType should not be null");
            }

            systemType = UdonSharpUtils.UserTypeToUdonType(systemType);

            return(GetTypeSymbol(systemType, context));
        }
コード例 #2
0
ファイル: ExternTypeSymbol.cs プロジェクト: ureishi/UdonSharp
        public ExternTypeSymbol(INamedTypeSymbol sourceSymbol, AbstractPhaseContext context)
            : base(sourceSymbol, context)
        {
            TryGetSystemType(sourceSymbol, out Type systemType);
            SystemType = systemType;

            Type udonType = UdonSharpUtils.UserTypeToUdonType(SystemType);

            UdonType = (ExternTypeSymbol)(udonType == SystemType ? this : context.GetUdonTypeSymbol(sourceSymbol));

            ExternSignature = CompilerUdonInterface.GetUdonTypeName(this);
        }
コード例 #3
0
        public void SetToType(System.Type type)
        {
            cSharpType = type;
            if (cSharpType != null && cSharpType.IsArray)
            {
                System.Type elementType = cSharpType;
                while (elementType.IsArray)
                {
                    elementType = elementType.GetElementType();
                }

                arrayElementMetadata = new TypeSerializationMetadata(elementType);
            }

            udonStorageType = UdonSharpUtils.UserTypeToUdonType(cSharpType);
        }
コード例 #4
0
        private void ConvertToUdonArrayElement(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 (targetArray == null || targetArray.Length != sourceArray.Length)
                {
                    targetElement = targetArray = (Array)Activator.CreateInstance(UdonSharpUtils.UserTypeToUdonType(cSharpType), sourceArray.Length);
                }

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

                    if (!UsbSerializationContext.CollectDependencies)
                    {
                        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");
            }
        }