/// <summary>
///讀取StreamingAssets中的文件
/// </summary>
/// <param name="path">StreamingAssets下的文件路徑</param>
/// <returns>讀取到的字符串</returns>
public static string GetTextForStreamingAssets(string path)
{
string localPath = "";
if (Application.platform == RuntimePlatform.Android)
{
localPath = Application.streamingAssetsPath + "/" + path;
}
else
{
localPath = "file:///" + Application.streamingAssetsPath + "/" + path;
}
WWW www = new WWW(localPath);
if (www.error != null)
{
Debug.LogError("error while reading files : " + localPath);
return ""; //讀取文件出錯
}
while (!www.isDone) { }
Debug.Log("File content : " + www.text);//www下面還有獲取字節數組的屬性
return www.text;
}