Unity WWW 和 AssetBundle只要将资源扔在服务器上就可以了吗?

答案肯定是否定的
一、为了实际验证这个功能的实际作用
1、一个服务器,一个域名:租个阿里云服务器(最低配置70多元一个月),买个域名
2、安装一个http服务器,我用的是Nginx服务器,具体Apache的服务不知道是怎么配置。
3、看了momo的AssetBundle功能介绍

二、功能实现-(服务器)
1、在服务器上创建个目录,然后把资源扔到服务器上去
这里写图片描述
这里我的服务器上的目录是(随意攻击人家的服务器是不道德的)
这里写图片描述

2、更改服务器上的配置文件,否则会报错403或者404,我的服务器配置是这样的,不懂服务器conf的去自学。。
Unity WWW 和 AssetBundle只要将资源扔在服务器上就可以了吗?_第1张图片
三、功能实现-(客户端)

public static readonly string PathURL = "http://wangpeng.online:10001/Prefab0.assetbundle";
void OnGUI()
    {
        if(GUILayout.Button("TestAssetBundle"))
        {
            StartCoroutine(LoadGameObject(PathURL));
        }
    }

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("Prefab0");
         //加载到游戏中   
         yield return Instantiate(obj0);
    } 
  

四、调用成功
后面那一句是加载的gameobject打印的,例子是momo的资源包
Unity WWW 和 AssetBundle只要将资源扔在服务器上就可以了吗?_第2张图片

你可能感兴趣的:(Unity)