private AssetBundleStatus LoadAssetBundle(string bundleName, AssetBundleWarehouse defaultWarehouse, out AssetBundleLoading operation, out string nameWithVariant, out AssetBundleWarehouse preferedWarehouse) { preferedWarehouse = FindWarehouse(bundleName, defaultWarehouse); nameWithVariant = preferedWarehouse.RemapBundleName(bundleName); if (_loadedAssetBundles.ContainsKey(nameWithVariant)) { operation = null; return(AssetBundleStatus.Loaded); } if (_loadingAssetBundleNames.Contains(nameWithVariant)) { operation = null; return(AssetBundleStatus.Loading); } if (_failedAssetBundleNames.Contains(nameWithVariant)) { operation = null; return(AssetBundleStatus.Failed); } _logger.InfoFormat("LoadAssetBundle :{0}", nameWithVariant); _loadingAssetBundleNames.Add(nameWithVariant); operation = preferedWarehouse.LoadAssetBundle(nameWithVariant); _loadingAssetBundles.AddLast(operation); return(AssetBundleStatus.Blank); }
public static AssetBundleWarehouse CreateWarehouse(AssetBundleWarehouseAddr addr, bool isLow) { AssetBundleWarehouse ret = null; switch (addr.Pattern) { case AssetBundleLoadingPattern.Simulation: ret = new SimulationWarehouse(addr, isLow); break; case AssetBundleLoadingPattern.AsyncLocal: ret = new AsyncLocalWarehouse(addr, isLow); break; case AssetBundleLoadingPattern.AsyncWeb: ret = new AsyncWebWarehouse(addr, isLow); break; case AssetBundleLoadingPattern.Sync: ret = new SyncWarehouse(addr, isLow); break; case AssetBundleLoadingPattern.EndOfTheWorld: throw new ArgumentException("AssetBundleLoadingPattern.EndOfTheWorld"); } return(ret); }
private AssetBundleStatus LoadAssetBundle(string bundleName, AssetBundleWarehouse defaultWarehouse, out AssetBundleLoading operation, out string nameWithVariant, out AssetBundleWarehouse preferedWarehouse) { if (string.IsNullOrEmpty(bundleName)) { operation = null; preferedWarehouse = null; nameWithVariant = bundleName; return(AssetBundleStatus.Failed); } preferedWarehouse = FindWarehouse(bundleName, defaultWarehouse); nameWithVariant = preferedWarehouse.RemapBundleName(bundleName); if (string.IsNullOrEmpty(nameWithVariant)) { operation = null; return(AssetBundleStatus.Failed); } if (_loadedAssetBundles.ContainsKey(nameWithVariant)) { operation = null; return(AssetBundleStatus.Loaded); } if (_loadingAssetBundleNames.Contains(nameWithVariant)) { operation = null; return(AssetBundleStatus.Loading); } if (_failedAssetBundleNames.Contains(nameWithVariant)) { operation = null; return(AssetBundleStatus.Failed); } _logger.DebugFormat("LoadAssetBundle :{0}", nameWithVariant); _loadingAssetBundleNames.Add(nameWithVariant); operation = null; try { operation = preferedWarehouse.LoadAssetBundle(nameWithVariant); _loadingAssetBundles.AddLast(operation); } catch (Exception e) { _logger.ErrorFormat("{0}", e); _loadingAssetBundleNames.Remove(nameWithVariant); _failedAssetBundleNames.Add(nameWithVariant); return(AssetBundleStatus.Failed); } return(AssetBundleStatus.Blank); }
public void LoadScene(string bundleName, string assetName, bool isAdditive) { string bundleNameWithVariant; if (LoadAssetBundle(bundleName, out bundleNameWithVariant) != AssetBundleStatus.Failed) { var warehouse = FindWarehouse(bundleName, _defaultWarehouse); _assetsWaitForBundle.AddLastExt(warehouse.LoadScene(bundleNameWithVariant, assetName, isAdditive)); } else { _assetsWaitForBundle.AddLastExt(AssetBundleWarehouse.LoadFailed(AssetLoadingPattern.Unkown, true, bundleName, assetName, null)); } }
public IEnumerator Init(bool isLow, string useMD5 = null) { _defaultWarehouse = WarehouseFactory.CreateWarehouse(_defaultWarehouseAddr, isLow, useMD5); var ret = _defaultWarehouse.Init(); if (ret != null) { _loadingAssetBundles.AddLast(ret.AssetBundleLoadingOperation); _assetsWaitForBundle.AddLastExt(ret.ManifestLoadingOperation); _loadingAssetBundleNames.Add(ret.ManifestLoadingOperation.BundleName); yield return(ret.ManifestLoadingOperation); _loadingAssetBundleNames.Remove(ret.ManifestLoadingOperation.BundleName); SetManifest(ret.ManifestLoadingOperation.LoadedAsset as AssetBundleManifest); _defaultWarehouse.SetManifest(ret.ManifestLoadingOperation.LoadedAsset as AssetBundleManifest); yield return(Clear()); } foreach (var addr in _supplementaryWarehouseAddr) { var warehouse = WarehouseFactory.CreateWarehouse(addr.Key, isLow); ret = warehouse.Init(); if (ret != null) { _loadingAssetBundles.AddLast(ret.AssetBundleLoadingOperation); _assetsWaitForBundle.AddLastExt(ret.ManifestLoadingOperation); _loadingAssetBundleNames.Add(ret.ManifestLoadingOperation.BundleName); yield return(ret.ManifestLoadingOperation); _loadingAssetBundleNames.Remove(ret.ManifestLoadingOperation.BundleName); SetManifest(ret.ManifestLoadingOperation.LoadedAsset as AssetBundleManifest); warehouse.SetManifest(ret.ManifestLoadingOperation.LoadedAsset as AssetBundleManifest); yield return(Clear()); } foreach (var bundle in addr.Value) { _supplementaryWarehouses.Add(bundle, warehouse); } } }
public void LoadAsset(string bundleName, string assetName, Type ObjectType) { string bundleNameWithVariant; AssetLoadingPattern LoadingPattern = AssetLoadingPattern.Unkown; if (LoadAssetBundle(bundleName, out bundleNameWithVariant) != AssetBundleStatus.Failed) { var warehouse = FindWarehouse(bundleName, _defaultWarehouse); var assetLoading = warehouse.LoadAsset(bundleNameWithVariant, assetName, ObjectType); if (warehouse is SimulationWarehouse) { LoadingPattern = AssetLoadingPattern.Simulation; } if (assetLoading != null) { _assetsWaitForBundle.AddLastExt(assetLoading); return; } } _assetsWaitForBundle.AddLastExt(AssetBundleWarehouse.LoadFailed(LoadingPattern, false, bundleName, assetName, ObjectType)); }
private AssetBundleWarehouse FindWarehouse(string bundleName, AssetBundleWarehouse defaultWarehouse) { var warehouse = defaultWarehouse; var baseName = Utility.GetNameWithoutVariant(bundleName); if (_supplementaryWarehouses.ContainsKey(baseName)) { warehouse = _supplementaryWarehouses[baseName]; } // else // { // foreach (var v in _supplementaryWarehouses) // { // if (baseName.StartsWith(v.Key)) // { // warehouse = v.Value; // break; // } // } // } return(warehouse); }