unityassetbundle 打包存放百度云加载

打包assetbundle程序

using UnityEngine;
using System.Collections;
using UnityEditor;

public class AssetBundleTest : Editor
{

    [MenuItem("Custom Editor/WebPlayer")]
    static void WebPlayer()
    {
        Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        foreach (Object obj in SelectedAsset)
        {
            string targetPath = Application.dataPath + "/Asset/" + obj.name + ".assetbundle";
            if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.WebPlayer))
            {
                Debug.Log(obj.name + "资源打包成功");
            }
            else
            {
                Debug.Log(obj.name + "资源打包失败");
            }
        }
        //刷新编辑器
        AssetDatabase.Refresh();
    }

    [MenuItem("Custom Editor/Android")]
    static void Android()
    {
        Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        foreach (Object obj in SelectedAsset)
        {
            string targetPath = Application.dataPath + "/Asset/" + obj.name + ".assetbundle";
            if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.Android))
            {
                Debug.Log(obj.name + "资源打包成功");
            }
            else
            {
                Debug.Log(obj.name + "资源打包失败");
            }
        }
        //刷新编辑器
        AssetDatabase.Refresh();
    }

   
}
加载程序

using UnityEngine;
using System.Collections;


public class loadModel : MonoBehaviour
{

        public string RUL = null;
        //"file://F:\\1.unity3d";
         WWW www;
        bool isDownLoad = false;
        public GameObject fatherObject;
        void Start()
        {
        StartCoroutine(LoadAssetbundle(RUL));
        }
         IEnumerator LoadAssetbundle(string url) 
         {
         // Start a download of the given URL
        // 开始从指定路径下载
         www = WWW.LoadFromCacheOrDownload(url, 1);
        // Wait for download to complete
        // 等待下载完成
        yield return www;
         if(!www.isDone)
         {
         print("123");
         }
        if (www.error != null)
        {
        Debug.Log (www.error);

        yield return null;
        }
// Instantiate(www.assetBundle.mainAsset);
 GameObject gameObj = GameObject.Instantiate(www.assetBundle.mainAsset, transform.position, Quaternion.identity) as GameObject;
 gameObj.transform.parent = fatherObject.transform;
 }
 void Update() 
 {
 if (!www.isDone)
 {
 isDownLoad = false;
 }
 else
 {
 isDownLoad = true;
 }


 }
 void OnGUI()
 {
 if(!isDownLoad)
 {
 GUI.Label(new Rect(720f / 1627.0f * Screen.width, 300f / 915.0f * Screen.height, 200f / 1627.0f * Screen.width, 50f / 915.0f * Screen.height), "正在下载请等待);
 }

 }
}





  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值