Application.persistentDataPath
这个路径在各平台下可以直接读取
string configPath = Application.persistentDataPath + "/config.xml";
File.WriteAllText(configPath, "hello world");
if (File.Exists(configPath))
{
string strxml = File.ReadAllText(configPath);
m_ContentTest.text = strxml;
}
Application.streamingAssetsPath
这个路径在Android平台下只能用www读取
public static string GetStreamingAssetPath()
{
string path = "";
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
path = "File://" + Application.streamingAssetsPath;
#elif UNITY_IPHONE
path = "file://" + Application.streamingAssetsPath;
#elif UNITY_ANDROID
path = Application.streamingAssetsPath;
#endif
return path;
}
public static string LoadStreamingAssetFileText(string fileName)
{
string configPath = GetStreamingAssetPath() + "/" + fileName;
WWW reader = new WWW(configPath);
while (!reader.isDone) { }
return reader.text;
}
streamingAssetsPath = jar:file:///mnt/asec/com.test.longshao-2/pkg.apk!/assets
dataPath = /mnt/asec/com.test.longshao-2/pkg.apk
persistentDataPath =/Android/data/包名/files
AssetBundle.LoadFromFile(path);
这个函数不能直接读streamingAssetsPath
而是要读 Application.dataPath + "!assets/具体文件目录/具体文件名"
例子:AssetBundle.LoadFromFile(Application.dataPath + "!assets/具体文件目录/具体文件名");
Unity3D各平台Application.xxxPath的路径
https://blog.csdn.net/ynnmnm/article/details/52253674
网友评论