Пример #1
0
        public void Read(AssetStream stream)
        {
            switch (Type.Type)
            {
            case PrimitiveType.Bool:
                if (IsArray)
                {
                    Value = stream.ReadBooleanArray();
                }
                else
                {
                    Value = stream.ReadBoolean();
                }
                stream.AlignStream(AlignType.Align4);
                break;

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

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

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

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

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

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

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

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

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

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

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

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

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