The good news: in Unity it's extremely easy to save/read text files.
The key point...
You must use Application.persistentDataPath (all platforms, all the time - no exceptions). "It's that simple!"
(A) There is utterly no reason, whatsoever, to use any other folders or paths.
(B) Indeed, you simply can not use any other folders or paths.
It's this easy to write and read files in Unity.
using System.IO;
// IO crib sheet..
//
// get the file path:
// f = Application.persistentDataPath+"/"+fileName;
//
// check if file exists: System.IO.File.Exists(f)
// write to file: File.WriteAllText(f,t)
// delete the file if needed: File.Delete(f)
// read from a file: File.ReadAllText(f)
That's all there is to it.
string currentText = File.ReadAllText(filePath);
Regarding the question here, "should I add them manually on the first run"
It's simple ...
public string GetThatXMLStuff()
{
f = Application.persistentDataPath+"/"+"defaults.txt";
// check if it already exists:
if ( ! System.IO.File.Exists(f) )
{
// First run. Put in the default file
string default = "First line of file.
";
File.WriteAllText(f, default);
}
// You know it exists no matter what. Just get the text:
return File.ReadAllText(f);
}
It's really that simple - nothing to it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…