如果是Unity,如何将文件路径保存到变量中?

时间:2020-07-03 07:32:39

标签: c# firebase unity3d

storage = Firebase.Storage.FirebaseStorage.DefaultInstance;
    storage_ref = storage.GetReferenceFromUrl("--");
    StorageReference dw = storage_ref.Child("Folder/"+PlayerPrefs.GetString("key")+".json");
    
    
   string local_url = Application.dataPath+"/Save Folder/"+storage_ref.Name; 
     // Start downloading a file
    Task task = storage_ref.GetFileAsync(default_path+storage_ref.Name,
   new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => {
    // called periodically during the download
   
    Debug.Log(string.Format(
      "Progress: {0} of {1} bytes transferred.",
      state.BytesTransferred,
      state.TotalByteCount
      
    ));
    
  }), CancellationToken.None);

task.ContinueWith(resultTask => {
  if (!resultTask.IsFaulted && !resultTask.IsCanceled) {
    
    Debug.Log("Download finished.");
    
  }
});

我尝试从Firebase存储下载文件。 但是未创建local_url文件。

我还尝试了local_url中的静态字符串路径,因此解决了这个问题。

1 个答案:

答案 0 :(得分:0)

如文档页面所述,不能保证Application.dataPath是可写的(特别是在iOS上它是只读的,在Android上它是APK或OBB [无法写入的不透明档案])

尝试切换到Application.persistentDataPath

string local_url = $"{Application.persistentDataPath}/Save Folder/{storage_ref.Name}";