首页 > 解决方案 > Unity 和 Oculus Go。在内部存储上读/写

问题描述

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

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

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

标签: androidunity3dstorageoculusoculusgo

解决方案


这是写函数:

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

推荐阅读