Unity和Oculus Go.读/写内部存储 [英] Unity and Oculus Go. Read/Write on the internal storage

查看:103
本文介绍了Unity和Oculus Go.读/写内部存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 !

推荐答案

这是写入功能:

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

这篇关于Unity和Oculus Go.读/写内部存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆