/// <summary> /// Loads the saved level. /// </summary> /// <param name='data'> The data describing the level to load </param> public static LevelLoader LoadSavedLevel(string data) { IsDeserializing = true; LevelData ld; if (data.StartsWith("NOCOMPRESSION")) { ld = UnitySerializer.Deserialize <LevelData>(Convert.FromBase64String(data.Substring(13))); } else { ld = UnitySerializer.Deserialize <LevelData>(SevenZipRadicalHelper.Decompress(Convert.FromBase64String(data), progressHelper)); } SaveGameManager.Loaded(); var go = new GameObject(); Object.DontDestroyOnLoad(go); var loader = go.AddComponent <LevelLoader>(); loader.Data = ld; Application.LoadLevel(ld.Name); return(loader); }
/// <summary> /// Serializes the level. /// </summary> /// <returns> The level stored as a string. </returns> /// <param name='urgent'> Whether to ignore an suspension of serialization </param> /// <exception cref='SerializationSuspendedException'>Is thrown when the serialization was suspended and urgent was not specified</exception> public static string SerializeLevel(bool urgent) { if (IsSuspended && !urgent) { if (SerializationMode == SerializationModes.CacheSerialization) { return(_cachedState.Data); } else { throw new SerializationSuspendedException(); } } //Try to get as much memory as possible Resources.UnloadUnusedAssets(); if (ShouldCollect) { GC.Collect(); } var data = SerializeLevel(false, null); //Free up memory that has been used during serialization if (ShouldCollect) { GC.Collect(); } if (useCompression) { return(Convert.ToBase64String( SevenZipRadicalHelper.Compress(data, progressHelper) )); } else { return("NOCOMPRESSION" + Convert.ToBase64String(data)); } }