tinkz
tinkz

Reputation: 120

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

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 :

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

Upvotes: 2

Views: 3384

Answers (3)

Doug Royer
Doug Royer

Reputation: 65

On the Oculus, you can read and write to Application.persistentDataPath. And you can only read from Application.streamingAssetsPath

I am not sure what failed. But I can r/w in the persistentDataPath.

Make sure you put a '/' between the directory and file name.

string FileName = Application.persistentDataPath + "/" + "file.txt";

Upvotes: 0

pale bone
pale bone

Reputation: 1836

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

Upvotes: 4

Richard Muthwill
Richard Muthwill

Reputation: 336

Try using Application.streamingAssetsPath.

Upvotes: 1

Related Questions