2017-04-06 12 views
1

私はプログラムを実行するために必要な情報を保持するためにストリーミングアセットフォルダを使用しています。以下は、使用するファイルパスを決定する方法です:ファイルのパスが見つからない場合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用に構築しようとしています。ここで

は、私は私が何を探していることはApplication.streamingAssetsPathだと思いUnity docs here

答えて

1

から使用するどのような経路で情報を得た

enter image description here

を取得していますエラーです。あなたはそれについてのより多くの情報を見つけることができますhere

あなたはAndroidを使用しているので、UnityのWWWクラスを使用してファイルを取得する必要があります。

EDIT:
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

関連する問題