zoukankan      html  css  js  c++  java
  • U3D assetbundle加载

     1 using UnityEngine;
     2 using System.Collections;
     3 public class testLoadFromAB : MonoBehaviour {
     4 
     5     IEnumerator DownloadAndCache()
     6     {
     7         while (!Caching.ready)
     8             yield return null;
     9 
    10         //注意,从本地加载时,必须使用前缀 file:///或file://,从网络加载则使用 http://,这两种协议可以在iphone和WINDOWS, 安卓上通用
    11         //UNITY MANUAL:
    12         //http://, https:// and file:// protocols are supported on iPhone. 
    13         //ftp:// protocol support is limited to anonymous downloads only. Other protocols are not supported.
    14         WWW www = WWW.LoadFromCacheOrDownload ("file:///Z:/unity/learn-test/Assets/AssetBundles/cubes.unity3d", 22);
    15         yield return www;
    16         if(!string.IsNullOrEmpty (www.error)){//有些平台不支持string为null,这种写法可以避免意外
    17             Debug.LogError (www.error);
    18             yield break;
    19         }
    20 
    21         AssetBundle bundle = www.assetBundle;
    22 
    23         //注意必须使用Instantiate实例化出来才能将两个CUBE显示到场景中
    24         GameObject cube1 = Instantiate (bundle.LoadAsset ("DecalCube2")) as GameObject;
    25         GameObject cube2 = Instantiate (bundle.LoadAsset ("DecalCube3")) as GameObject;
    26 
    27     }
    28     // Use this for initialization
    29     void Start () {
    30         StartCoroutine ("DownloadAndCache");
    31     }
    32     
    33     // Update is called once per frame
    34     void Update () {
    35     
    36     }
    37 }
  • 相关阅读:
    大工程(bzoj 3611)
    消耗战(bzoj 2286)
    Computer(hdu 2196)
    文件排版(codevs 1300)
    洛谷 P2015 二叉苹果树
    洛谷 P2014 选课
    洛谷 P1352 没有上司的舞会
    COGS 505. 城市
    洛谷 P1306 斐波那契公约数
    洛谷 P1962 斐波那契数列
  • 原文地址:https://www.cnblogs.com/timeObjserver/p/5987341.html
Copyright © 2011-2022 走看看