Window弹出Import/Export统一

Window Pop-up Import/Export Unity

我已经完成了一个导入和导出脚本,其中 imports/exports 一个包含所有当前生成的对象及其 XYZ 坐标的文件。但是,仍然存在问题。导出时我现在正在做的是自动将文件保存在“Application.persistentDataPath”中,但是我期待有一个 window 弹出窗口并要求您将文件保存在您的 PC 上的哪个位置用于导入。

导入导出代码如下:

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

为此有一个内置的编辑器实用程序,称为 EditorUtility.SaveFilePanel 请参阅文档 here

用于导入 EditorUtility.OpenFilePanel

请注意,这些方法将一直阻塞,直到用户选择了一条路径,return 用户选择了该路径。如果操作被取消,空字符串是 returned。