Ejemplo n.º 1
0
 public void LoadBundleAsset(string bundleName, string assetName, Action <UnityEngine.Object> loadcallback, bool isCache = false)
 {
     // 判断AB包是否已加载
     if (_AssetBundlePool.BundleIsLoaded(bundleName))
     {
         AssetBundleItem    bundleItem = _AssetBundlePool.GetBundleItem(bundleName);
         UnityEngine.Object obj        = bundleItem.LoadAsset(assetName, isCache);
         loadcallback(obj);
     }
     else
     {
         // 创建AB包加载完毕回调
         Action <bool, string> bundleLoadCallback = delegate(bool succeed, string assetbundleName)
         {
             // 如果加载成功
             if (succeed)
             {
                 AssetBundleItem    abItem = _AssetBundlePool.GetBundleItem(assetbundleName);
                 UnityEngine.Object obj    = abItem.LoadAsset(assetName, isCache);
                 loadcallback(obj);
             }
             else
             {
                 loadcallback(null);
             }
         };
         // 先加载AB包
         LoadBundle(bundleName, bundleLoadCallback);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 同步加载ab包资源
 /// </summary>
 /// <param name="bundleName">包名</param>
 /// <param name="assetName">资源名</param>
 /// <returns></returns>
 public UnityEngine.Object LoadBundleAssetSync(string bundleName, string assetName, bool cache = false)
 {
     if (_AssetBundlePool.BundleIsLoaded(bundleName))
     {
         return(_AssetBundlePool.GetBundleItem(bundleName).LoadAsset(assetName, cache));
     }
     else
     {
         AssetBundleItem bundleItem = LoadBundleSync(bundleName);
         if (bundleItem != null)
         {
             return(bundleItem.LoadAsset(assetName, cache));
         }
         else
         {
             return(null);
         }
     }
 }