/// <summary> /// 获取带有子物体的资源 /// </summary> /// <param name="assetname">资源名称</param> /// <returns>所有资源</returns> public Object[] LoadAssetWithSubAssets(string assetbundlename, string assetname) { //先判断缓存层有没有缓存 if (NameAndCacheDict.ContainsKey(assetbundlename)) { //有缓存直接获取资源 Object[] assets = NameAndCacheDict[assetbundlename].GetAsset(assetname); //安全校验,排除缓存层存在但是资源不存在的情况 if (assets != null) { return(assets);//因为是获取带有子物体的资源,所以返回Object数组 } } //当前AB包没有被加载 if (!NameAndBundleDict.ContainsKey(assetbundlename)) { Debug.LogError("当前" + assetbundlename + "包没有加载,无法获取资源"); return(null); } else { //当前AB包已经被加载了,则获取带有子物体的资源数组 Object[] asset = NameAndBundleDict[assetbundlename].LoadAssetWithSubAssets(assetname); //封装该资源 TempObject tempAsset = new TempObject(asset); //缓存层已经被创建,缓存层里也有资源,但是我们要获取的那个资源不存在缓存层中 if (NameAndCacheDict.ContainsKey(assetbundlename)) { //直接把资源加入缓存层中 NameAndCacheDict[assetbundlename].AddAsset(assetname, tempAsset); } else { //第一次获取AB包里的资源,缓存层没有被创建,则新建一个缓存层 AssetCache cache = new AssetCache(); //把资源加入缓存层中 cache.AddAsset(assetname, tempAsset); //将缓存层保存到字典里 NameAndCacheDict.Add(assetbundlename, cache); } //返回带有子物体的资源数组 return(asset); } }