使用Unity时,读取程序包内部资源的时候,如果使用了www的方法,需要注意在手机平台上的前缀转换.
以下的代码可以获取程序包的目录
public static string AppContentPath() {
string path = string.Empty;
switch (Application.platform) {
case RuntimePlatform.Android:
path = "jar:file://" + Application.dataPath + "!/assets/";
break;
case RuntimePlatform.IPhonePlayer:
path = "file://" + Application.dataPath + "/Raw/";
break;
default:
path = "file://" + Application.dataPath + "/StreamingAssets/";
break;
}
return path;
}
一下代码获取可写的目录
public static string DataPath {
get {
string game = SimpleFramework.AppConst.AppName.ToLower();
if (Application.platform == RuntimePlatform.IPhonePlayer ||
Application.platform == RuntimePlatform.Android ||
Application.platform == RuntimePlatform.WP8Player)
{
return Application.persistentDataPath + "/" + game + "/"; //"/sdcard/" + game + "/";
}
//Test for lua update in the editor env, after debug, it should be if (Const.SimulateMode)
if (SimpleFramework.AppConst.SimulationMode)
{
string target = string.Empty;
target = game;
return Application.dataPath + "/../SimulatorDataPath/" + target + "/";
}
return "c:/" + game + "/";
}