1

我开发了一个用于研究目的的 Unity 游戏。玩家每关需要的时间写在一个 txt 文件中。在 PC 上它工作正常。但是,当我在 PC 上使用 sidequest 或 android 文件传输读取 Oculus 文件时,我无法在任何地方找到它。我将 Unity 中的权限更改Project Settings -> Write PermissionExternal(SD)并在 Android Manifest.xml 中添加了以下行:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

我还尝试了所有可能的路径(Application.dataPath,Application.persistentDataPath/sdcard/filename, /mnt/sdcard/filename,...) 我还重新启动了 Oculus 几次。

这是我正在创建和保存 txt 的代码:

if (SceneManager.GetActiveScene().name == "Level1")
        {
            //Path of the file
            string path = Application.dataPath + "/SteamingAssets/CoordinateTimeLog" + ".txt";
            //Create file if it doesn't exist
            if(!File.Exists(path)){
                File.WriteAllText(path, "Path the Player walked (x,y,z) + Time in seconds\n\n");
            }
            //Content of the file
            string content = "Level 1: " + transform.position +"   "+ System.DateTime.Now + "\n\n";
            //Add coordinates to it
            File.AppendAllText(path, content);
        }

在 AndroidManifest.xml 中,我在下面添加了以下内容</application>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

有人能帮我吗?

4

0 回答 0