简体   繁体   中英

Window Pop-up Import/Export Unity

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 = "";
    ...
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM