Nel*_* Yi 3 c# unity-game-engine hololens
我正在尝试在hololens上创建一个应用程序,用于创建和写入文本文件以记录用户的输入.目前,我一直试图制作文件并从文件资源管理器或一个驱动器访问它.这是我的方法:
public void createFile()
{
#if WINDOWS_UWP
Task task = new Task(
async () =>
{
testText.text="hi";
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile textFileForWrite = await storageFolder.CreateFileAsync("Myfile.txt");
});
task.Start();
task.Wait();
#endif
}
Run Code Online (Sandbox Code Playgroud)
这基本上就是我在这里找到的:https://forums.hololens.com/discussion/1862/how-to-deploy-and-read-data-file-with-app,但当我尝试运行该方法时,应用程序在hololens冻结一点然后关闭.代码有问题吗?知道发生了什么事吗?提前致谢
在Unity中,您可以使用Application.persistentDataPath:https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
在Device Portal/File Explorer中,它映射到LocalAppData/YourApp/LocalState.下面的代码会在那里写"MyFile.txt".
using System.IO;
string path = Path.Combine(Application.persistentDataPath, "MyFile.txt");
using (TextWriter writer = File.CreateText(path))
{
// TODO write text here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3066 次 |
| 最近记录: |