Example #1
0
        public void Read(AssetReader reader)
        {
            switch (Type)
            {
            case PrimitiveType.Bool:
                if (IsArray)
                {
                    Value = reader.ReadBooleanArray();
                }
                else
                {
                    Value = reader.ReadBoolean();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Char:
                if (IsArray)
                {
                    Value = reader.ReadCharArray();
                }
                else
                {
                    Value = reader.ReadChar();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.SByte:
                if (IsArray)
                {
                    Value = reader.ReadByteArray();
                }
                else
                {
                    Value = reader.ReadSByte();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Byte:
                if (IsArray)
                {
                    Value = reader.ReadByteArray();
                }
                else
                {
                    Value = reader.ReadByte();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Short:
                if (IsArray)
                {
                    Value = reader.ReadInt16Array();
                }
                else
                {
                    Value = reader.ReadInt16();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.UShort:
                if (IsArray)
                {
                    Value = reader.ReadUInt16Array();
                }
                else
                {
                    Value = reader.ReadUInt16();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Int:
                if (IsArray)
                {
                    Value = reader.ReadInt32Array();
                }
                else
                {
                    Value = reader.ReadInt32();
                }
                break;

            case PrimitiveType.UInt:
                if (IsArray)
                {
                    Value = reader.ReadUInt32Array();
                }
                else
                {
                    Value = reader.ReadUInt32();
                }
                break;

            case PrimitiveType.Long:
                if (IsArray)
                {
                    Value = reader.ReadInt64Array();
                }
                else
                {
                    Value = reader.ReadInt64();
                }
                break;

            case PrimitiveType.ULong:
                if (IsArray)
                {
                    Value = reader.ReadUInt64Array();
                }
                else
                {
                    Value = reader.ReadUInt64();
                }
                break;

            case PrimitiveType.Single:
                if (IsArray)
                {
                    Value = reader.ReadSingleArray();
                }
                else
                {
                    Value = reader.ReadSingle();
                }
                break;

            case PrimitiveType.Double:
                if (IsArray)
                {
                    Value = reader.ReadDoubleArray();
                }
                else
                {
                    Value = reader.ReadDouble();
                }
                break;

            case PrimitiveType.String:
                if (IsArray)
                {
                    Value = reader.ReadStringArray();
                }
                else
                {
                    Value = reader.ReadString();
                }
                break;

            case PrimitiveType.Complex:
                if (IsArray)
                {
                    int count = reader.ReadInt32();
                    ISerializableStructure[] structures = new ISerializableStructure[count];
                    for (int i = 0; i < count; i++)
                    {
                        ISerializableStructure structure = ComplexType.CreateDuplicate();
                        structure.Read(reader);
                        structures[i] = structure;
                    }
                    Value = structures;
                }
                else
                {
                    ISerializableStructure structure = ComplexType.CreateDuplicate();
                    structure.Read(reader);
                    Value = structure;
                }
                break;

            default:
                throw new NotImplementedException($"Unknown {nameof(PrimitiveType)} '{Type}'");
            }
        }