Ejemplo n.º 1
0
 internal virtual void Load()
 {
     if (LWUtility.loadDelegate != null)
     {
         asset = LWUtility.loadDelegate(url, assetType);
     }
 }
Ejemplo n.º 2
0
/**
 *      public void Initialize(Action onSuccess, Action<string> onError)
 *      {
 *
 *          if (string.IsNullOrEmpty(LWUtility.dataPath)) LWUtility.dataPath = Application.streamingAssetsPath;
 *
 *          LWDebug.Log(string.Format("Init->assetBundleMode: {0} | dataPath :{1}| connServer :{2}", LWUtility.GlobalConfig.assetBundleMode, LWUtility.dataPath, LWUtility.GlobalConfig.connServer), LogColor.green);
 *
 *          if (LWUtility.GlobalConfig.assetBundleMode)
 *          {
 *              updatePath = LWUtility.updatePath;
 *              var platform = LWUtility.GetPlatform();
 *              //默认资源路径
 *              var path = Path.Combine(LWUtility.dataPath, Path.Combine(LWUtility.AssetBundles, platform)) +
 *                         Path.DirectorySeparatorChar;
 *              Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL;
 *
 *              Bundles.Initialize(path, platform, () =>
 *              {
 *                  var asset = LoadAsync(LWUtility.AssetsManifestAsset, typeof(Manifest));
 *                  asset.completed += obj =>
 *                  {
 *                      var manifest = obj.asset as Manifest;
 *                      if (manifest == null)
 *                      {
 *                          if (onError != null) onError("manifest == null");
 *                          return;
 *                      }
 *
 *                      if (string.IsNullOrEmpty(LWUtility.downloadURL))  //将下载地址放在全局配置文件中
 *                          LWUtility.downloadURL = manifest.downloadURL;
 *                      Bundles.activeVariants = manifest.activeVariants;
 *                      _bundles = manifest.bundles;
 *                      var dirs = manifest.dirs;
 *                      _bundleAssets = new Dictionary<string, int>(manifest.assets.Length);
 *                      for (int i = 0, max = manifest.assets.Length; i < max; i++)
 *                      {
 *                          var item = manifest.assets[i];
 *                          _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle;
 *                      }
 *
 *                      if (onSuccess != null)
 *                          onSuccess();
 *                      obj.Release();
 *                  };
 *              }, onError);
 *          }
 *          else
 *          {
 *              if (onSuccess != null)
 *                  onSuccess();
 *          }
 *      }
 *
 */
        public async UniTask <AssetsManagerRequest> InitializeAsync()
        {
            AssetsManagerRequest assetsManagerRequest = new AssetsManagerRequest {
                isSuccess = true
            };


            if (string.IsNullOrEmpty(LWUtility.dataPath))
            {
                LWUtility.dataPath = Application.streamingAssetsPath;
            }

            LWDebug.Log(string.Format("Init->assetBundleMode {0} | dataPath {1}", LWUtility.GlobalConfig.assetBundleMode, LWUtility.dataPath), LogColor.green);
            //判断当前是否为AB模式
            if (LWUtility.GlobalConfig.assetBundleMode)
            {
                updatePath = LWUtility.updatePath;
                var platform = LWUtility.GetPlatform();
                //默认资源路径
                var path = Path.Combine(LWUtility.dataPath, Path.Combine(LWUtility.AssetBundles, platform)) + Path.DirectorySeparatorChar;
                Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL;
                //初始化Bundles
                BundleRequest bundleRequest = await Bundles.Initialize(path, platform);

                //Bundle加载出错
                if (bundleRequest.error != null)
                {
                    assetsManagerRequest.isSuccess = false;
                    assetsManagerRequest.error     = bundleRequest.error;
                    bundleRequest.Release();
                    bundleRequest = null;
                    return(assetsManagerRequest);
                }
                else
                {
                    //加载资源的Manifest文件
                    var assetRequest = await LoadAsyncTask <Manifest>(LWUtility.AssetsManifestAsset);

                    var manifest = assetRequest.asset as Manifest;
                    if (manifest == null)
                    {
                        assetsManagerRequest.isSuccess = false;
                        assetsManagerRequest.error     = "manifest == null";
                        return(assetsManagerRequest);
                    }
                    //设置资源的下载地址,在编辑器下会读取当前Assets下的Manifest。
                    if (string.IsNullOrEmpty(LWUtility.downloadURL))
                    {
                        LWUtility.downloadURL = manifest.downloadURL;
                    }
                    Bundles.activeVariants = manifest.activeVariants;
                    _bundles = manifest.bundles;
                    var dirs = manifest.dirs;
                    _bundleAssets = new Dictionary <string, int>(manifest.assets.Length);
                    for (int i = 0, max = manifest.assets.Length; i < max; i++)
                    {
                        var item = manifest.assets[i];
                        _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle;
                    }

                    assetRequest.Release();
                    bundleRequest.Release();
                    bundleRequest = null;
                    return(assetsManagerRequest);
                }
            }
            else
            {
                return(assetsManagerRequest);
            }
        }