public void Write(Transform cameraPivot, VoxelArray voxelArray)
    {
        if (voxelArray.IsEmpty())
        {
            Debug.Log("World is empty! File will not be written.");
            return;
        }

        JSONObject root = new JSONObject();

        root["writerVersion"]    = VERSION;
        root["minReaderVersion"] = FILE_MIN_READER_VERSION;

        JSONObject camera = new JSONObject();

        camera["pan"]    = WriteVector3(cameraPivot.position);
        camera["rotate"] = WriteQuaternion(cameraPivot.rotation);
        camera["scale"]  = cameraPivot.localScale.z;
        root["camera"]   = camera;

        root["world"] = WriteWorld(voxelArray);

        string filePath = WorldFiles.GetFilePath(fileName);

        using (FileStream fileStream = File.Create(filePath))
        {
            using (var sw = new StreamWriter(fileStream))
            {
                sw.Write(root.ToString());
                sw.Flush();
            }
        }
    }
Beispiel #2
0
    public static void Write(string filePath, Transform cameraPivot, VoxelArray voxelArray)
    {
        if (voxelArray.IsEmpty())
        {
            Debug.Log("World is empty! File will not be written.");
            return;
        }
        Debug.Log("Writing MessagePack file " + filePath);

        var world       = WriteWorld(cameraPivot, voxelArray);
        var worldObject = new MessagePackObject(world);

        using (FileStream fileStream = File.Create(filePath))
        {
            fileStream.WriteByte((byte)'m');
            var packer = Packer.Create(fileStream, PackerCompatibilityOptions.None);
            worldObject.PackToMessage(packer, null);
        }
    }