示例#1
0
 static LevelSerializer()
 {
     LevelSerializer.allPrefabs            = new Dictionary <string, GameObject>();
     LevelSerializer.IgnoreTypes           = new HashSet <string>();
     LevelSerializer.CustomSerializers     = new Dictionary <Type, IComponentSerializer>();
     LevelSerializer.PlayerName            = string.Empty;
     LevelSerializer.SaveResumeInformation = true;
     LevelSerializer.SerializationMode     = LevelSerializer.SerializationModes.CacheSerialization;
     LevelSerializer.MaxGames         = 20;
     LevelSerializer.SavedGames       = new Index <string, List <LevelSerializer.SaveEntry> >();
     LevelSerializer._stopCases       = new List <Type>();
     LevelSerializer.createdPlugins   = new List <object>();
     LevelSerializer.useCompression   = false;
     LevelSerializer.webClient        = new WebClient();
     LevelSerializer.Guard            = new object();
     LevelSerializer._collectionCount = 0;
     LevelSerializer.Deserialized     = delegate
     {
     };
     LevelSerializer.GameSaved = delegate
     {
     };
     LevelSerializer.SuspendingSerialization = delegate
     {
     };
     LevelSerializer.ResumingSerialization = delegate
     {
     };
     LevelSerializer.StoreComponent = delegate
     {
     };
     LevelSerializer.Progress = delegate
     {
     };
     LevelSerializer.webClient.UploadDataCompleted   += new UploadDataCompletedEventHandler(LevelSerializer.HandleWebClientUploadDataCompleted);
     LevelSerializer.webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(LevelSerializer.HandleWebClientUploadStringCompleted);
     LevelSerializer._stopCases.Add(typeof(PrefabIdentifier));
     UnitySerializer.AddPrivateType(typeof(AnimationClip));
     Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
     for (int i = 0; i < assemblies.Length; i++)
     {
         Assembly assembly = assemblies[i];
         UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
         {
             LevelSerializer.createdPlugins.Add(Activator.CreateInstance(tp));
         }, assembly, typeof(SerializerPlugIn));
         UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
         {
             LevelSerializer.CustomSerializers[((ComponentSerializerFor)attr).SerializesType] = (Activator.CreateInstance(tp) as IComponentSerializer);
         }, assembly, typeof(ComponentSerializerFor));
     }
     LevelSerializer.AllPrefabs = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast <GameObject>().Where(delegate(GameObject go)
     {
         PrefabIdentifier component = go.GetComponent <PrefabIdentifier>();
         return(component != null && !component.IsInScene());
     }).Distinct(LevelSerializer.CompareGameObjects.Instance).ToDictionary((GameObject go) => go.GetComponent <PrefabIdentifier>().ClassId, (GameObject go) => go);
     try
     {
         string @string = PlayerPrefsFile.GetString("_Save_Game_Data_", string.Empty, true);
         if (!string.IsNullOrEmpty(@string))
         {
             try
             {
                 LevelSerializer.SavedGames = UnitySerializer.Deserialize <global::Lookup <string, List <LevelSerializer.SaveEntry> > >(Convert.FromBase64String(@string));
             }
             catch
             {
                 LevelSerializer.SavedGames = null;
             }
         }
         if (LevelSerializer.SavedGames == null)
         {
             LevelSerializer.SavedGames = new Index <string, List <LevelSerializer.SaveEntry> >();
             LevelSerializer.SaveDataToPlayerPrefs();
         }
     }
     catch
     {
         LevelSerializer.SavedGames = new Index <string, List <LevelSerializer.SaveEntry> >();
     }
 }
示例#2
0
    static JSONLevelSerializer()
    {
        JSONLevelSerializer.Deserialized = delegate
        {
        };
        JSONLevelSerializer.GameSaved = delegate
        {
        };
        JSONLevelSerializer.SuspendingSerialization = delegate
        {
        };
        JSONLevelSerializer.ResumingSerialization = delegate
        {
        };
        JSONLevelSerializer.StoreComponent = delegate
        {
        };
        JSONLevelSerializer._collectionCount = 0;
        JSONLevelSerializer.Progress         = delegate
        {
        };
        WebClient webClient = JSONLevelSerializer.webClient;

        if (JSONLevelSerializer.< > f__mg$cache0 == null)
        {
            JSONLevelSerializer.< > f__mg$cache0 = new UploadDataCompletedEventHandler(JSONLevelSerializer.HandleWebClientUploadDataCompleted);
        }
        webClient.UploadDataCompleted += JSONLevelSerializer.< > f__mg$cache0;
        WebClient webClient2 = JSONLevelSerializer.webClient;

        if (JSONLevelSerializer.< > f__mg$cache1 == null)
        {
            JSONLevelSerializer.< > f__mg$cache1 = new UploadStringCompletedEventHandler(JSONLevelSerializer.HandleWebClientUploadStringCompleted);
        }
        webClient2.UploadStringCompleted += JSONLevelSerializer.< > f__mg$cache1;
        JSONLevelSerializer._stopCases.Add(typeof(PrefabIdentifier));
        UnitySerializer.AddPrivateType(typeof(AnimationClip));
        foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
            {
                JSONLevelSerializer.createdPlugins.Add(Activator.CreateInstance(tp));
            }, assembly, typeof(SerializerPlugIn));
            UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
            {
                JSONLevelSerializer.CustomSerializers[((ComponentSerializerFor)attr).SerializesType] = (Activator.CreateInstance(tp) as IComponentSerializer);
            }, assembly, typeof(ComponentSerializerFor));
        }
        JSONLevelSerializer.AllPrefabs = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast <GameObject>().Where(delegate(GameObject go)
        {
            PrefabIdentifier component = go.GetComponent <PrefabIdentifier>();
            return(component != null && !component.IsInScene());
        }).Distinct(JSONLevelSerializer.CompareGameObjects.Instance).ToDictionary((GameObject go) => go.GetComponent <PrefabIdentifier>().ClassId, (GameObject go) => go);
        try
        {
            string @string = PlayerPrefs.GetString("JSON_Save_Game_Data_");
            if (!string.IsNullOrEmpty(@string))
            {
                JSONLevelSerializer.SavedGames = UnitySerializer.JSONDeserialize <global::Lookup <string, List <JSONLevelSerializer.SaveEntry> > >(@string);
            }
            if (JSONLevelSerializer.SavedGames == null)
            {
                JSONLevelSerializer.SavedGames = new Index <string, List <JSONLevelSerializer.SaveEntry> >();
            }
        }
        catch
        {
            JSONLevelSerializer.SavedGames = new Index <string, List <JSONLevelSerializer.SaveEntry> >();
        }
    }