Unity3D多平台——预编译相关宏定义

平台

功能
UNITY_EDITOR 编辑器调用
UNITY_EDITOR_OSX 专门为Mac OS(包括Universal,PPC和Intelarchitectures)平台的定义
UNITY_EDITOR_WIN Windows操作系统
UNITY_STANDALONE_LINUX Linux的独立应用程序
UNITY_STANDALONE_OSX 用于专门为Mac OS X
UNITY_STANDALONE_WIN 用于专门为Windows独立应用程序
UNITY_STANDALONE 独立的平台(Mac,Windows或Linux)
UNITY_WII Wii游戏平台
UNITY_IOS iPhone平台
UNITY_ANDROID Android平台
UNITY_PS4 用于运行PlayStation 4
UNITY_XBOXONE Xbox One  
UNITY_WEBGL WebGL
UNITY_FACEBOOK Facebook平台
UNITY_EDITOR_WIN Windows上编辑器
UNITY_EDITOR_OSX Mac OS X上编辑器

Android平台对应路径:

Application.dataPath : /data/app/xxx.xxx.xxx.apk

Application.streamingAssetsPath :  jar:file:///data/app/xxx.xxx.xxx.apk/!/assets

Application.persistentDataPath :  /data/data/xxx.xxx.xxx/files

Application.temporaryCachePath :  /data/data/xxx.xxx.xxx/cache

IOS平台对应路径:

Application.dataPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data

Application.streamingAssetsPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw

Application.persistentDataPath :Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents

Application.temporaryCachePath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches

Windows Web Player平台对应路径:

Application.dataPath :  file:///D:/MyGame/WebPlayer (即导包后保存的文件夹,html文件所在文件夹)

Application.streamingAssetsPath : 

Application.persistentDataPath : 

Application.temporaryCachePath : 

一、在项目根目录种创建Resources文件夹来保存文件。

可以使用Resources.Load("文件名,注:不包括文件后缀名");把文件夹中的对象加载出来。

二、直接放在项目根路径下来保存文件

在直接使用Application.dataPath来读取文件进行操作。

注:移动端是没有访问权限的。

三、在项目根目录中创建StreamingAssets文件夹保存文件

使用Application.streamingAssetsPath来读取文件进行操作。

注:此方法在Pc/Mac电脑中可实现对文件实施"增删改查"等操作,但在移动端只支持读取操作。

四、使用Application.persistentDataPath来操作文件

该文件文在手机沙盒中,因为不能直接存放文件,

1.通过服务器直接下载保存到该位置,也可以通过Md5码比对下载更新新的资源

2.没有服务器的,只有简介通过文件流的方式从本地读取并写入Application.persistentDataPath文件下,然后通过Application.persistentDataPath来读取操作。

注:在Pc/Mac电脑 以及Android跟Ipad、iPhone都可对文件进行任意操作,另外在IOS上该目录下的东西可以被iCloud自动备份。

StreamingAssets的通常路径:

string path =

#if UNITY_ANDROID && !UNITY_EDITOR//安卓平台

Application.streamingAssetsPath + "/Josn/modelname.json";

#elif UNITY_IOS && !UNITY_EDITOR//IOS平台

"file://" + Application.streamingAssetsPath + "/Josn/modelname.json";

#elif UNITY_STANDLONE_WIN||UNITY_EDITOR//PC端

"file://" + Application.streamingAssetsPath + "/Josn/modelname.json";

#else

string.Empty;

#endif

猜你喜欢

转载自blog.csdn.net/peng_1993/article/details/91413123
今日推荐