[Serializable]
public class Users
{
public string Name;
public string Password;
}
public class RegPanel : MonoBehaviour
{
public InputField nameTxt, passwordTxt;
//存储
public void Reg ()
{
string path = Application.dataPath + "/Json/users.txt";
Users u = new Users();
u.Name = nameTxt.text;
u.Password = passwordTxt.text;
string s = JsonUtility.ToJson(u)+"\n";
File.AppendAllText(path, s);
}
//读取
public void Login()
{
string path = Application.dataPath + "/Json/users.txt";
string[] s = File.ReadAllLines(path);
for (int i = 0; i < s.Length; i++)
{
Users u = JsonUtility.FromJson<Users>(s[i]);
print(u.Name + "\t" + u.Password);
}
}
}