provencesl/Rank-System

rank

Opened this issue · 0 comments

[Serializable]
public class Score
{
private string level;
private string time;

public string Level()
{
	return this.level;
}
public string Time()
{
	return this.time;
}

public Score(string level, string time)
{
	this.level = level;
	this.time = time;
}

}

[Serializable]
public class Score
{
public string level;
public string time;

public Score(string level, string time)
{
    this.level = level;
    this.time = time;
}

}

[Serializable]
public class ScoreList
{
public List scoreList;

public ScoreList(List<Score> scoreList)
{
    this.scoreList = scoreList;
}

}

public string SerializeToJson()
{
List scoreList = new List();
scoreList.Add(new Score("1","00:20"));
scoreList.Add(new Score("1", "00:30"));
scoreList.Add(new Score("2", "00:20"));
scoreList.Add(new Score("3", "00:20"));

    ScoreList scoreContainer = new ScoreList(scoreList);
    string json = JsonUtility.ToJson(scoreContainer,false);

    if (!File.Exists(jsonPath))
    {
        Debug.Log("Create File");
        File.Create(jsonPath);
    }

   

    try
    {
        //StreamWriter sw = new StreamWriter(jsonPath);
        ////sw.WriteLine(json);
        //sw.Write(json);
        ////注意写入数据以后关闭
        //sw.Close();

        //Resources.Load
        //File.WriteAllText(jsonPath, json);
    }
    catch (Exception e)
    {
        Debug.Log(e.Message);
    }

    //File.WriteAllText(jsonPath,json);

    Debug.Log("json:" + json);
    return json;

}

private List<Score> ConstructData()
{
	List<Score> list = new List<Score>();

	Score score1 = new Score("1","00:20");
	Score score2 = new Score("1","00:30");
	Score score3 = new Score("2","00:20");
	list.Add(score1);
	list.Add(score2);
	list.Add(score3);

	Debug.Log("score1:" + "level:"+ score1.Level()+"time:" + score1.Time());

	for (int i = 0; i < list.Count; i++)
	{
		Debug.Log("level:" + list[i].Level() + "Time:" + list[i].Time());
	}

	return list;
}