2

我正在使用 Unity 构建一个 Oculus Go 应用程序。我正在尝试在 GO 的内部存储中创建一个 txt 文件。(将 HMD 插入 PC 时看到的那个)。

我尝试了那些不同的路径,它们似乎都不起作用:

  • Application.persistentDataPath
  • /mnt/sdcard/myFolder
  • //storage/emulated/0/Android/data/myFolder.

如果有人知道正确的那会很酷谢谢!

4

2 回答 2

4

这是写函数:

File.WriteAllText(Path.Combine(_directoryPath, fileName), _text, System.Text.Encoding.ASCII);

这是读取函数:

#if PLATFORM_ANDROID && !UNITY_EDITOR
        TextAsset textAsset = new TextAsset(System.IO.File.ReadAllText(filePathAndName));
#elif UNITY_EDITOR
        TextAsset textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(filePathAndName);
#endif

这是使用的路径:

#if PLATFORM_ANDROID && !UNITY_EDITOR
        SavedTextsCompleteFilePath = Application.persistentDataPath;

        // just for debugging and playing in the editor
#elif UNITY_EDITOR
        SavedTextsCompleteFilePath = "Assets/Resources";
#endif
        // set the base file path, then add the directory if it's not there yet
        SavedTextsCompleteFilePath = MakeFolder(SavedTextsCompleteFilePath, "MyGameSaveFolder");
    }

和辅助功能:

private string MakeFolder(string path, string savedTextsFolder)
{
    string saveDirectory = path + savedTextsFolder;
    if (!Directory.Exists(saveDirectory))
    {
        Directory.CreateDirectory(saveDirectory);
        Debug.Log("directory created! at: " + path);
    }
    return saveDirectory;
}
于 2018-09-10T15:58:28.833 回答
1

尝试使用Application.streamingAssetsPath.

于 2018-09-09T21:12:21.220 回答