1.本地txt存储数据
/// <summary>
/// 书写文本
/// </summary>
/// <param name="fileName"></param>
/// <param name="s"></param>
public void WriteTXT(string fileName, string s)
{
string url = "";
if (Application.platform == RuntimePlatform.Android)
{
url = Application.persistentDataPath + "/" + fileName;
}
else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
{
url = Application.streamingAssetsPath + "/" + fileName;
}
if (File.Exists(url))
{
Debug.Log("已存在");
File.WriteAllText(url, string.Empty);//清空一次
File.WriteAllText(url, s);
return;
}
else
{
FileStream fs = new FileStream(url, FileMode.Create);
fs.Close();
File.WriteAllText(url, string.Empty);//清空一次
File.WriteAllText(url, s);
Debug.Log("创建");
}
}
/// <summary>
/// 读取文本
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public string LoadTXTtoString(string fileName)
{
string url = "";
string s = "";
if (Application.platform == RuntimePlatform.Android)
{
url = Application.persistentDataPath + "/" + fileName;
}
else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
{
url = Application.streamingAssetsPath + "/" + fileName;
}
s = File.ReadAllText(url);
return s;
}
2.PlayerPrefs注册列表存储数据
PlayerPrefs.SetInt("HuiYiShiID", id);
PlayerPrefs.SetString("HuiYiShiData", data);
PlayerPrefs.GetInt("HuiYiShiID");
PlayerPrefs.GetString("HuiYiShiData");