unity不同平臺下訪問遊戲中檔案的路徑
有時候我們會在打包ab以後的資料夾中放入一些配置檔案,通過讀取這個檔案裡的一些內容來改變遊戲裡的一些東西。
如下圖“conf”這個檔案,
在不同平臺下訪問的路徑也會不一樣,下面的程式碼分別對應不同的路徑
string head =
#if UNITY_EDITOR
@"file://";
#elif UNITY_ANDROID
"jar:file://";
#elif UNITY_IPHONE
"file://"
#elif UNITY_STANDALONE_WIN
"file:///";
#else
"";
#endif
string path = "";
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXEditor)
{
path = string.Format("{0}/StreamingAssets/", Application.dataPath);
}
else if (Application.platform == RuntimePlatform.Android)
{
path = string.Format("{0}!/assets/", Application.dataPath);
}
else if (Application.platform == RuntimePlatform.IPhonePlayer)
{
path = string.Format("{0}/Raw/", Application.dataPath);
}
WWW www= new WWW(head+path+"conf.txt");
while(!www.isDone)
{
}
讀取www