I have done an import and export script which imports/exports a file with all current spawned objects and their XYZ coordinates. However, there's still an issue. What I am doing now when exporting is saving the file in "Application.persistentDataPath" automatically, however I am looking forward to have a window pops-up and requests you where to save the file on your PC and same for importing.
Here's the code of importing and exporting:
public void WriteString(string message)
{
// string path = Application.persistentDataPath "/" display.text ".txt";
string path = Application.persistentDataPath "/txt.txt";
//Write some text to the test.txt file
StreamWriter writer = new StreamWriter(path, true);
writer.WriteLine(message);
writer.Close();
StreamReader reader = new StreamReader(path);
//Print the text from the file
Debug.Log(reader.ReadToEnd());
reader.Close();
}
public void ReadString()
{
// string path = Application.persistentDataPath "/" display.text ".txt";
string path = Application.persistentDataPath "/txt.txt";
StreamReader reader = new StreamReader(path);
string line = "";
...
}
CodePudding user response:
There is a builtin editor utility for this, called EditorUtility.SaveFilePanel
See the documentation here.
For importing use EditorUtility.OpenFilePanel
.
Note that these methods will block until the user selects a path and return that path when they did so. If the action is cancelled, an empty string is returned.