Unity and Oculus Go. Read/Write on the internal storage

只谈情不闲聊 提交于 2020-01-01 03:45:27

问题


I'm building a Oculus Go App with Unity. I'm trying to create a txt file in the internal storage of the GO. (The one you see when you plug the HMD to your PC).

I tried those differents paths, none of them seems to work :

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

If someone knows the correct one that would be cool Thank you !


回答1:


This is the write function:

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

This is the read function:

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

This is the path to use:

#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");
    }

and the helper function:

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:


Try using Application.streamingAssetsPath.



来源:https://stackoverflow.com/questions/51599050/unity-and-oculus-go-read-write-on-the-internal-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!