【问题标题】:Unity and Oculus Go. Read/Write on the internal storageUnity 和 Oculus Go。在内部存储上读/写
【发布时间】:2019-01-07 00:06:03
【问题描述】:

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

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

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

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

【问题讨论】:

  • 我也在尝试这样做,您介意同时分享您的读/写功能吗?

标签: android unity3d storage oculus oculusgo


【解决方案1】:

这是写函数:

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

【讨论】:

    【解决方案2】:

    尝试使用Application.streamingAssetsPath

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
    • 操作员要了一个目录,我给了他他要的东西
    • 然后相应地写下你的答案。您写的是“怎么办”,而不是“使用它会起作用”。 “怎么样”(还有@JosephSible 编辑的“尝试使用”)暗示它可能不起作用,并且您希望 OP 做出响应(例如,检查并返回报告是否有效) .这使它成为评论,而不是答案。如果这是 the 解决方案,请说明清楚,以免审阅者误判。对给定解决方案为什么以及如何工作的正确解释,即使是像特定路径这样简单的解决方案,总是最好的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多