美文网首页
Unity 在各个平台下的读取

Unity 在各个平台下的读取

作者: jojo911 | 来源:发表于2019-07-26 16:58 被阅读0次

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

相关文章

网友评论

      本文标题:Unity 在各个平台下的读取

      本文链接:https://www.haomeiwen.com/subject/vuudrctx.html