unity不同平台下访问游戏中文件的路径

来源:互联网 发布:手机wifi扫描不到网络 编辑:程序博客网 时间:2024/06/08 17:36

有时候我们会在打包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

阅读全文
1 0