public class PlayerInfo
{
public int SerialNum;
public string ID:
public int HitNum;
public int DiglettCount;
public int AwardNum;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using LitJson;
public class PlayerInfoCtrl : Monobehaviour
{
private PlayerInfo cInfo = new PlayerInfo();
public PlayerInfo CurrentPlayer
{
get{return cInfo;}
}
string path = Application.dataPath + "/playerInfo.json";
void Load()
{
string[] AllPlayerInfos = File.ReadAllLines(Path);
List<PlayerInfo> dateList = new List<PlayerInfo>();
foreach(var v in AllPlayerInfos)
{
PlayerInfo info = JsonMapper.ToObject<PlayerInfo>(v);
dateList.Add(info);
}
}
void Save()
{
List<string> infolist;
if(File.Exists(path))
{
string[] AllPlayerInfos = File.ReadAllLines(path);
infolist = new List<string>(AllPlayerInfos);
if(AllPlayerInfos!=null)
{
cInfo.SeriaNum = AllPlayerInfos.Length + 1;
}
}
else
{
infolist = new List<string>();
cInfo.SerialNum = 1;
}
PlayerInfo info = new PlayerInfo();
string nowInfo = JsonMapper.ToJson(info);
infolist.Add(nowInfo);
File.WriteAllLines(path,infolist.ToArray());
}
}