Unity StreamingAssets文件加載的注意事項

 當我們從StreamingAssets中加載資源時,需要注意的一點是,Windows平台與macOS平台的資源路徑格式並不相同,比如在macOS中使用StreamingAssets路徑時,需要注意在路徑前加入“file://”,否則Unity將不會正常加載資源(Windows平台不需要,但加入"file://"後不會影響Windows平台正常訪問該路徑)。

string.Format("{0}/{1}",  Application.streamingAssetsPath, filePath)

string.Format("file://{0}/{1}"Application.streamingAssetsPathfilePath)

OR

$"file://{Application.streamingAssetsPath}/{filePath}" 

(Unity官方在文檔中並沒有提到這種格式差異。 )

留言