赞
踩
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using UnityEngine.Networking; /* * Author:W * mainfenst文件 */ public class AssetBundleManager : MonoBehaviour { private AssetBundle shareAb = null; private AssetBundle ab = null; // Start is called before the first frame update void Start() { //加载mainfest的AB包。并获取到其中mainfest文件,从而知晓项目中所有AB包以及他们之间的依赖关系 AssetBundle assetBundle = LoadAssetBundleFromFile("AssetBundles/AssetBundles"); AssetBundleManifest assetBundleManifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest"); //打印所有AB名 foreach (string abName in assetBundleManifest.GetAllAssetBundles()) { Debug.Log("AB包名:"+abName); } //获取cubewall包依赖的所有AB包,并进行加载 string[] depenABs = assetBundleManifest.GetAllDependencies("walls/cubewall.unityobj"); foreach (string name in depenABs) { Debug.Log("walls/cubewall.unityobj包所依赖的包:"+name); LoadAssetBundleFromFile("AssetBundles/"+name); } //再加载cubewall包本身 AssetBundle wallAB = LoadAssetBundleFromFile("AssetBundles/walls/cubewall.unityobj"); //实例化 GameObject wallPrefab = wallAB.LoadAsset<GameObject>("CubeWall"); Instantiate(wallPrefab); } /// <summary> /// AB加载方式2:从本地文件夹中加载【同步】 /// </summary> /// <returns></returns> private AssetBundle LoadAssetBundleFromFile(string path) { AssetBundle ab = null; ab = AssetBundle.LoadFromFile(path); return ab; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。