protected void Start() { IDeserializable[] children = this.transform.GetComponentsInChildren <IDeserializable>(); DeserMap map = new DeserMap(); this.BuildPath(); try{ using (Stream sr = File.OpenRead(this.searchPath)){ var serde = new DataContractJsonSerializer(map.GetType()); map = (DeserMap)serde.ReadObject(sr); } } catch (ArgumentException e) { Debug.LogError(e); } catch (IOException _e) { File.Create(this.searchPath); } foreach (var entry in map.GetInner()) { for (int i = 0; i < children.Length; i++) { if (children[i].Hash() == entry.Key) { children[i].SetProperty(entry.Value); break; } } } }
public void SaveGame(Deser deser) { string json = "[" + lang.ToString() + "," + lastLevel.ToString() + "," + volume.ToString() + "]"; var map = new DeserMap(); map.Add(((IDeserializable)(this)).Hash(), json); deser.Save(map, "savegame.json"); }
public void Save(DeserMap map, string path) { var writePath = "." + sep + "Data" + sep + path; try{ using (Stream sw = File.OpenWrite(writePath)){ var serde = new DataContractJsonSerializer(map.GetType()); serde.WriteObject(sw, map); } } catch (ArgumentException e) { Debug.LogError(e); } catch (IOException _e) { File.Create(this.searchPath); } }