コード例 #1
0
        public LevelEditorCustomData Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(new LevelEditorCustomData());
            }

            options.Security.DepthStep(ref reader);

            object value = null;
            Type   type  = null;

#if ALE_COMPATIBILITY_0
            LevelEditorSerializerOptions levelEditorOptions = options as LevelEditorSerializerOptions;
            if (levelEditorOptions != null && levelEditorOptions.SaveVersion == 0)
            {
                DeserializeFormat0(ref reader, options, ref type, ref value);
            }
            else
#endif
            {
                DeserializeFormat1(ref reader, options, ref type, ref value);
            }

            reader.Depth--;

            return(new LevelEditorCustomData(type, value));
        }
コード例 #2
0
 private static void SetCompression(bool compress)
 {
     if (compress != previousCompress)
     {
         previousCompress = compress;
         Options          = (LevelEditorSerializerOptions)Options.WithCompression(compress ? MessagePackCompression.Lz4Block : MessagePackCompression.None);
     }
 }
コード例 #3
0
        public LevelEditorSaveData Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            options.Security.DepthStep(ref reader);

            ushort saveVersion = 0;
            string name        = null;
            List <LevelEditorObjectData> objects = null;
            Dictionary <string, LevelEditorCustomData> customData = null;

            LevelEditorSerializerOptions levelEditorOptions = options as LevelEditorSerializerOptions;

            if (levelEditorOptions != null)
            {
                levelEditorOptions.SaveVersion = 0;
            }
            int count = reader.ReadArrayHeader();

            for (int i = 0; i < count; i++)
            {
                switch (i)
                {
                case 0:
#if ALE_COMPATIBILITY_0
                    // This used to be name in save format 0.
                    if (reader.NextMessagePackType == MessagePackType.String)
                    {
                        name = reader.ReadString();
                    }
                    else
#endif
                    {
                        saveVersion = reader.ReadUInt16();
                    }

                    if (levelEditorOptions != null)
                    {
                        levelEditorOptions.SaveVersion = saveVersion;
                    }

                    break;

                case 1:
#if ALE_COMPATIBILITY_0
                    // This used to be objects in save format 0.
                    if (saveVersion == 0)
                    {
                        objects = options.Resolver.GetFormatterWithVerify <List <LevelEditorObjectData> >().Deserialize(ref reader, options);
                    }
                    else
#endif
                    {
                        name = reader.ReadString();
                    }

                    break;

                case 2:
#if ALE_COMPATIBILITY_0
                    // This used to be customData in save format 0.
                    if (saveVersion == 0)
                    {
                        customData = options.Resolver.GetFormatterWithVerify <Dictionary <string, LevelEditorCustomData> >().Deserialize(ref reader, options);
                    }
                    else
#endif
                    {
                        objects = options.Resolver.GetFormatterWithVerify <List <LevelEditorObjectData> >().Deserialize(ref reader, options);
                    }

                    break;

                case 3:
                    customData = options.Resolver.GetFormatterWithVerify <Dictionary <string, LevelEditorCustomData> >().Deserialize(ref reader, options);
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }

            reader.Depth--;

            return(new LevelEditorSaveData(name)
            {
                objects = objects, customData = customData
            });
        }