Unity 和 Oculus Go。 Read/Write 在内部存储上
Unity and Oculus Go. Read/Write on the internal storage
我正在使用 Unity 构建 Oculus Go 应用程序。
我正在尝试在 GO 的内部存储中创建一个 txt 文件。
(将 HMD 插入 PC 时看到的那个)。
我尝试了这些不同的路径,none 似乎可行:
- Application.persistentDataPath
- /mnt/sdcard/myFolder
- //storage/emulated/0/Android/data/myFolder.
如果有人知道正确的那个就好了
谢谢!
尝试使用 Application.streamingAssetsPath
。
这是写函数:
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 应用程序。 我正在尝试在 GO 的内部存储中创建一个 txt 文件。 (将 HMD 插入 PC 时看到的那个)。
我尝试了这些不同的路径,none 似乎可行:
- Application.persistentDataPath
- /mnt/sdcard/myFolder
- //storage/emulated/0/Android/data/myFolder.
如果有人知道正确的那个就好了 谢谢!
尝试使用 Application.streamingAssetsPath
。
这是写函数:
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;
}