1.在unity中打好包
得到.unity3d后缀文件
2.上传到服务器中
我使用的是iis服务器(如何搭服务器可百度),上传方法是直接用qq的文件传输(有点丢人),将文件放到C:\inetpub\wwwroot(也就是iis服务器向外部开放的那个文件夹)。
3.设置服务器
主要是使服务器支持.unity3d后缀下载,否则后面下ab包的时候疯狂404。
3.1 运行mmc
3.2 文件-添加/删除管理单元-添加iis服务器
成功后是这样的:
3.3 选择mme类型(下图红圈)
3.4 添加.unity3d后缀,后面填application/octet-stream
4.从客户端下载对应ab包(加载代码如下)
using UnityEngine; using System.Collections; public class ABMono : MonoBehaviour { void Start () { string res = "45.40.193.251/cube.unity3d"; StartCoroutine(LoadALLGameObject(res)); } private IEnumerator LoadALLGameObject(string path) { WWW bundle = new WWW(path); yield return bundle; if (!string.IsNullOrEmpty(bundle.error)) { Debug.Log("ERROR:" + bundle.error); } else { Debug.Log("SUCCESS TO DOWNLOAD:" + bundle.bytesDownloaded); } yield return 0; //通过Prefab的名称把他们都读取出来 Object obj0 = bundle.assetBundle.LoadAsset("Cube.prefab"); GameObject.Instantiate(obj0); //加载到游戏中 yield return Instantiate(obj0); } }
服务器我先开着(攻击是不道德滴),资源也还在,用上面的代码应该可以直接下载对应的ab包。