/* * セーブデータを読み込む */ public void Load() { bool is_shown_map = (SceneManager.GetActiveScene().name == RoomMapper.SCENE_NAME); string packPath = this.MAPPED_OBJECTS_PACK_PATH + this.mappedJsonName; string allText = File.ReadAllText(packPath); this.pack = MappedObjectsPack.CreateFromJSON(allText); Dictionary <string, GameObject> mappingObjs = this.GetMappingObjects(); for (int i = 0; i < this.pack.objPositions.Count; i++) { string name = this.pack.objNames[i]; if (mappingObjs.ContainsKey(name)) { GameObject anObj = mappingObjs[name]; anObj.transform.position = this.pack.objPositions[i]; anObj.transform.rotation = this.pack.objRotations[i]; anObj.transform.localScale = this.pack.objScales[i]; anObj.transform.parent = this.mapped.transform; } else { Debug.Log("Error: object " + name + " doesn't exist."); continue; } } }
public static MappedObjectsPack CreateFromJSON(string json) { MappedObjectsPack pack = null; try { pack = JsonUtility.FromJson <MappedObjectsPack>(json); } catch (Exception e) { Debug.Log("JsonUtilityオブジェクトへの変換エラー" + e.Message); } return(pack); }
/* * データをPlayerPrefsXに保存する */ public void Save() { this.MapSelectingObjects(); //選択したオブジェクトをマッピングする this.pack = new MappedObjectsPack(); foreach (Transform transform in this.mapped.transform) { this.pack.objNames.Add(transform.gameObject.name); this.pack.objPositions.Add(transform.position); this.pack.objRotations.Add(transform.rotation); this.pack.objScales.Add(transform.localScale); } string savingData = this.pack.ToJSON(); string packPath = this.MAPPED_OBJECTS_PACK_PATH + this.mappedJsonName; File.WriteAllText(packPath, savingData); Debug.Log("Data is saved in " + packPath); }