关于移动平台路径

来源:互联网 发布:程序员个人工作体会 编辑:程序博客网 时间:2024/04/30 02:23

关于移动平台路径

1、下面这段代码是要要得到本地路径,如果没有的话,会创建该路径

//----------------------------得到本地路径------------------------------    public static string GetLocalPath()    {string path = "";string filepath = "jar:file://" + Application.dataPath + "!/assets/";#if UNITY_ANDROIDpath = "jar:file://" + Application.dataPath + "!/assets/";#elif UNITY_IPHONE  path = Application.persistentDataPath;#elif UNITY_STANDALONE_WIN || UNITY_EDITOR       path =  Application.dataPath;#else       //string.Empty;#endif        string dataFilePath = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);        dataFilePath = dataFilePath.Substring(0, dataFilePath.LastIndexOf(Path.DirectorySeparatorChar));        if (dataFilePath.EndsWith(".app"))        {            dataFilePath = dataFilePath.Substring(0, dataFilePath.LastIndexOf(Path.DirectorySeparatorChar));        }        string dataPath = dataFilePath + Path.DirectorySeparatorChar + "Documents";        if (!Directory.Exists(dataPath))        {            Directory.CreateDirectory(dataPath);        }        return dataPath + Path.DirectorySeparatorChar;    }

2、下面的这段代码是使用www加载本地资源时写的,基本都会用到的

//www 加载本地文件路径    public static string GetLocalPathByWWW()    {        string path = "file://" + Application.streamingAssetsPath;#if UNITY_EDITOR        path = "file://" + Application.streamingAssetsPath;#elif UNITY_ANDROID        path= "jar:file://" + Application.dataPath + "!/assets";#elif UNITY_IPHONE        path = "file://" + Application.streamingAssetsPath;#endif        return path;    }
3、下面这段代码是在嵌入网页时加载本地网页写的,没办法UNiwebview只是别安卓的这个路径
 public static string GetUrl()    {        string path = "file://" + Application.streamingAssetsPath;#if UNITY_EDITOR        path = "file://" + Application.streamingAssetsPath;#elif UNITY_ANDROID        path= "file:///android_asset";#elif UNITY_IPHONE        path = "file://" + Application.streamingAssetsPath;#endif        return path;    }



0 0
原创粉丝点击