// // Parse JSON data // public void parseJson(string json) { int i, len; LevelVoxelChunk levelVoxelChunk; LevelProp levelProp; //Debug.Log (json); JSONNode data = JSON.Parse(json); fileFormatVersion = -1; if (data ["v"] != null) { fileFormatVersion = Int32.Parse(data ["v"]); } levelId = -1; if (data ["id"] != null) { levelId = Int32.Parse(data ["id"]); } levelPos = new DataTypeVector3(); if (data ["pos"] != null) { if (data ["pos"] ["x"] != null) { levelPos.x = (float)data ["pos"] ["x"]; } if (data ["pos"] ["y"] != null) { levelPos.y = (float)data ["pos"] ["y"]; } if (data ["pos"] ["z"] != null) { levelPos.z = (float)data ["pos"] ["z"]; } } levelName = ""; if (data ["n"] != null) { levelName = data ["n"]; } levelVoxelChunks = new List <LevelVoxelChunk> (); if (data ["chunks"] != null) { JSONArray chunks = (JSONArray)data ["chunks"]; if (chunks != null) { len = chunks.Count; for (i = 0; i < len; ++i) { levelVoxelChunk = new LevelVoxelChunk(); levelVoxelChunk.parseJson(chunks [i]); levelVoxelChunks.Add(levelVoxelChunk); } } } levelProps = new List <LevelProp> (); if (data ["props"] != null) { JSONArray props = (JSONArray)data ["props"]; if (props != null) { len = props.Count; for (i = 0; i < len; ++i) { levelProp = new LevelProp(); levelProp.parseJson(props [i]); levelProps.Add(levelProp); } } } playerPosition = new DataTypeVector3(); playerPosition.x = 0; playerPosition.y = 0; playerPosition.z = 0; if (data ["p"] != null) { if (data ["p"] ["x"] != null) { playerPosition.x = (float)data ["p"] ["x"]; } if (data ["p"] ["y"] != null) { playerPosition.y = (float)data ["p"] ["y"]; } if (data ["p"] ["z"] != null) { playerPosition.z = (float)data ["p"] ["z"]; } } playerEuler = new DataTypeVector3(); playerEuler.x = 0; playerEuler.y = 0; playerEuler.z = 0; if (data ["r"] != null) { if (data ["r"] ["x"] != null) { playerEuler.x = (float)data ["r"] ["x"]; } if (data ["r"] ["y"] != null) { playerEuler.y = (float)data ["r"] ["y"]; } if (data ["r"] ["z"] != null) { playerEuler.z = (float)data ["r"] ["z"]; } } }
// private LevelFile createLevelData(string levelName) { LevelFile levelFile = new LevelFile(); levelFile.fileFormatVersion = Globals.levelSaveFormatVersion; levelFile.levelId = -1; levelFile.levelName = levelName; levelFile.levelPos = new DataTypeVector3(); levelFile.levelPos.x = 0; levelFile.levelPos.y = 0; levelFile.levelPos.z = 0; levelFile.playerPosition = new DataTypeVector3(); levelFile.playerPosition.x = FlyCam.Instance.player.position.x; levelFile.playerPosition.y = FlyCam.Instance.player.position.y; levelFile.playerPosition.z = FlyCam.Instance.player.position.z; levelFile.playerEuler = new DataTypeVector3(); levelFile.playerEuler.x = FlyCam.Instance.player.eulerAngles.x; levelFile.playerEuler.y = FlyCam.Instance.player.eulerAngles.y; levelFile.playerEuler.z = FlyCam.Instance.player.eulerAngles.z; levelFile.levelVoxelChunks = new List <LevelVoxelChunk> (); VoxelsLevelChunk vlc = LevelEditor.Instance.curVoxelsLevelChunk; VoxelUtils.VoxelChunk vc; int i, len = vlc.aVoxelChunks.Count; for (i = 0; i < len; ++i) { vc = vlc.aVoxelChunks [i]; LevelVoxelChunk voxelChunk = new LevelVoxelChunk(); voxelChunk.position = new DataTypeVector3(); voxelChunk.position.x = vc.pos.x; voxelChunk.position.y = vc.pos.y; voxelChunk.position.z = vc.pos.z; voxelChunk.size = new DataTypeVector3(); voxelChunk.size.x = vc.size.x; voxelChunk.size.y = vc.size.y; voxelChunk.size.z = vc.size.z; voxelChunk.materialId = vc.materialIndex; levelFile.levelVoxelChunks.Add(voxelChunk); } // PROPS List <LevelProp> levelProps = new List <LevelProp> (); Dictionary <GameObject, worldProp> worldProps = LevelEditor.Instance.curVoxelsLevelChunk.worldProps; foreach (KeyValuePair <GameObject, worldProp> p in worldProps) { worldProp prop = p.Value; if (!prop.go.activeSelf) { continue; } int propId = prop.id; if (propId <= 0) { continue; } LevelProp levelProp = new LevelProp(); levelProp.id = propId; levelProp.position = new DataTypeVector3(); levelProp.position.x = prop.go.transform.position.x; levelProp.position.y = prop.go.transform.position.y; levelProp.position.z = prop.go.transform.position.z; levelProp.rotation = new DataTypeQuaternion(); levelProp.rotation.w = prop.go.transform.rotation.w; levelProp.rotation.x = prop.go.transform.rotation.x; levelProp.rotation.y = prop.go.transform.rotation.y; levelProp.rotation.z = prop.go.transform.rotation.z; levelProps.Add(levelProp); } levelFile.levelProps = levelProps; return(levelFile); }