2017-04-06 145 views
1

因此,我正在使用流資產文件夾來存放我需要運行我的程序的一些信息。這裏是我如何確定使用的文件路徑:Android未找到文件路徑Unity 5

// Location of the top part of the query 
    public string fileLocation_queryTop = "/Bro/bro_Headers_TOP.json";   

    // We are on android 
    if(Application.platform == RuntimePlatform.Android) 
    { 
     assetPath = "jar:file://" + Application.dataPath + "!/assets"; 
    } 
    // We are on iPhone 
    else if(Application.platform == RuntimePlatform.IPhonePlayer) 
    { 
     assetPath = Application.dataPath + "/Raw"; 
    } 
    // We are on mac or windows 
    else 
    { 
     assetPath = Application.dataPath + "/StreamingAssets"; 
    } 

    _query_TOP = File.ReadAllText(assetPath + fileLocation_queryTop); 

這在Windows上正常工作,但我想今天爲Android構建。

這裏是我得到

enter image description here

我就從Unity docs here

回答

1

我猜你正在尋找的是Application.streamingAssetsPath使用什麼路徑信息錯誤。你可以找到更多關於它的信息here

既然你是在Android上,你將不得不使用Unity的WWW類來檢索你的文件。

編輯:
this link你只需要調整的文件名,並把結果保存在您的_query_TOP變量。

private IEnumerator LoadFile() 
{ 
    string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "file.txt"); 

    if(filePath.Contains("://")) 
    { 
     WWW www = new WWW(filePath); 
     yield return www; 
     if(string.IsNullOrEmpty(www.error)) 
     { 
      _query_TOP = www.text; 
     } 
    } 
    else 
    { 
     _query_TOP = System.IO.File.ReadAllText(filePath); 
    } 
} 
+0

我需要爲iOS使用WWW嗎? – BenjaFriend

+0

你總是可以嘗試使用'System.IO',但由於資產也包裝在iOS上(至少我認爲),我會說是的。也使用** WWW **往往是一個好主意:) – Kardux

+0

好酷,謝謝!我會給它一個 – BenjaFriend

相關問題