public List <string> BuildWorld(Transform cameraPivot, VoxelArray voxelArray, bool editor) { this.editor = editor; MessagePackObjectDictionary worldDict = worldObject.AsDictionary(); CheckWorldValid(worldDict); fileWriterVersion = worldDict[FileKeys.WORLD_WRITER_VERSION].AsInt32(); EntityReference.ResetEntityIds(); try { ReadWorld(worldDict, cameraPivot, voxelArray); } catch (MapReadException e) { throw e; } catch (Exception e) { throw new MapReadException("Error reading world file", e); } EntityReference.DoneLoadingEntities(); return(warnings); }
public List <string> BuildWorld(Transform cameraPivot, VoxelArray voxelArray, bool editor) { this.editor = editor; JSONObject root = rootNode.AsObject; if (root == null || root["writerVersion"] == null || root["minReaderVersion"] == null) { throw new MapReadException("Invalid world file"); } if (root["minReaderVersion"].AsInt > VERSION) { throw new MapReadException("This world file requires a newer version of the app"); } fileWriterVersion = root["writerVersion"].AsInt; EntityReference.ResetEntityIds(); try { if (editor && cameraPivot != null && root["camera"] != null) { ReadCamera(root["camera"].AsObject, cameraPivot); } if (root["world"] != null) { ReadWorld(root["world"].AsObject, voxelArray); } } catch (MapReadException e) { throw e; } catch (Exception e) { throw new MapReadException("Error reading world file", e); } EntityReference.DoneLoadingEntities(); return(warnings); }
// return warnings public List <string> Read(Transform cameraPivot, VoxelArray voxelArray, bool editor) { this.editor = editor; if (missingMaterial == null) { // allowTransparency is true in case the material is used for an overlay, so the alpha value can be adjusted missingMaterial = ResourcesDirectory.MakeCustomMaterial(ColorMode.UNLIT, true); missingMaterial.color = Color.magenta; } string jsonString; try { string filePath = WorldFiles.GetFilePath(fileName); using (FileStream fileStream = File.Open(filePath, FileMode.Open)) { using (var sr = new StreamReader(fileStream)) { jsonString = sr.ReadToEnd(); } } } catch (Exception e) { throw new MapReadException("An error occurred while reading the file", e); } JSONNode rootNode; try { rootNode = JSON.Parse(jsonString); } catch (Exception e) { throw new MapReadException("Invalid world file", e); } if (rootNode == null) { throw new MapReadException("Invalid world file"); } JSONObject root = rootNode.AsObject; if (root == null || root["writerVersion"] == null || root["minReaderVersion"] == null) { throw new MapReadException("Invalid world file"); } if (root["minReaderVersion"].AsInt > VERSION) { throw new MapReadException("This world file requires a newer version of the app"); } fileWriterVersion = root["writerVersion"].AsInt; EntityReference.ResetEntityIds(); try { if (editor && cameraPivot != null && root["camera"] != null) { ReadCamera(root["camera"].AsObject, cameraPivot); } if (root["world"] != null) { ReadWorld(root["world"].AsObject, voxelArray); } } catch (MapReadException e) { throw e; } catch (Exception e) { throw new MapReadException("Error reading world file", e); } EntityReference.DoneLoadingEntities(); return(warnings); }