转载自:http://blog.csdn.net/usopp_dream/article/details/40381177?utm_source=tuicool&utm_medium=referral
~~~~~题外~~~~~
公司工作机不能上外网,疏于整理自己所学的知识,导致很多知识点了解过多次,仍然遗忘。慢慢开始下班后在家整理吧~~
正题
unity3d有四种加载机制:
- //服务器地址样例
- string sUrl = "http://192.168.X.X/hss"+"/test.assetbundle";
- //本地地址样例
- /*****
- * 对于不同平台 Application.persistentDataPath 路径都有读写权限(需要多线程下载的兄妹们的福音)
- * 不同平台的assetbundle文件要在不同的平台打包,用unity的不同平台building的文件是不行的
- * e.g. ios平台的assetbundle文件必须在ios系统的机器上用unity打包生成(坑了很久)
- *****/
- string sLocalUrl = "file://"+Application.persistentDataPath+"/test.assetbundle";
- // method 1
- /******
- *异步
- *******/
- WWW www = new WWW (sUrl);
- yield return www;
- // method 2 == method 1
- /******
- *异步
- *******/
- WWW www2 = WWW.LoadFromCacheOrDownload(sUrl,0);
- yield return www2;
- // method 3
- /******
- *同步
- *******/
- AssetBundle.CreateFromFile(sUrl);
- // method 4
- /******
- *异步
- *******/
- byte[] bs = File.ReadAllBytes (sLocalUrl);
- AssetBundleCreateRequest abq = AssetBundle.CreateFromMemory(bs);
- yield return abq;
- // 加载到游戏中
- AssetBundle ab = www.assetBundle;
- // abq.assetBundle;
- GameObject Gobj = ab.Load ("name") as GameObject;// name是预设中obj的名字
- Instantiate (Gobj);