android - Unity 和 Oculus Go。读/写内部存储器

标签 android unity-game-engine storage oculus oculusgo

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

我尝试了这些不同的路径,但似乎都不起作用:

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

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

最佳答案

这是写入函数:

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;
}

关于android - Unity 和 Oculus Go。读/写内部存储器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51599050/

相关文章:

javascript - JS - 防止鼠标离开屏幕

Java-数据存储和自动运行程序?

java - Android ButterKnife NullPointer 在 CustomAdapter 中绑定(bind)

android - 为什么Unity打开其他应用后又回到android下的Unity后Unity的功能被阻止了

android - 在模块中找到重复的类 com.mapbox.android.telemetry.AlarmReceiver。 Mapbox 安卓工作室

unity-game-engine - Unity OpenXR 从 VR Controller 读取触发器和 handle 数据

database - 在数据库中存储图像——是还是不是?

android - 无法在我的设备 android 上写入 SD 卡

android - FirebaseRecyclerAdapter 更新时会闪烁我的行

android - Radio Group - 获取选定的 ID