Exemple #1
0
    public GLOBAL_PARA.CubePoint LoadCubePoint()
    {
        StreamReader   streamReader = new StreamReader(Application.dataPath + @"/Data/" + songInfo.songName + ".json");
        JsonSerializer serializer   = new JsonSerializer();

        serializer.NullValueHandling = NullValueHandling.Ignore;
        JsonReader reader = new JsonTextReader(streamReader);

        GLOBAL_PARA.CubePoint cubePoint = serializer.Deserialize <GLOBAL_PARA.CubePoint>(reader);
        return(cubePoint);
    }
Exemple #2
0
    /// <summary>
    /// 将CubePoint转换成json字符串并保存到本地
    /// </summary>
    /// <param name="cubePoint">需要保存的CubePoint</param>
    public void SaveCubePoint(GLOBAL_PARA.CubePoint cubePoint)
    {
        //存储的文件名,后面有多首歌曲的话改用歌曲的名字命名
        string filePath = Application.dataPath + @"/Data/" + songInfo.songName + ".json";
        //找到当前路径
        FileInfo file = new FileInfo(filePath);
        //判断有没有该文件,有则打开文件,没有创建后打开文件
        StreamWriter sw = file.CreateText();
        //将对象转换成json字符串
        string objJsonStr = JsonConvert.SerializeObject(cubePoint);

        //输出文件
        sw.WriteLine(objJsonStr);
        //释放资源
        sw.Close();
        sw.Dispose();
    }