IEnumerator LoadManifestBundle() { // SINGLE "Android" or "iOS" manifest string url = manifestBundleBaseURL; #if UNITY_ANDROID url += "Android/Android"; #elif UNITY_IOS url += "iOS/iOS"; #endif //AssetBundle manifestBundle = AssetBundle.LoadFromFile(manifestBundlePath); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { Debug.LogError("Failed to load AssetBundle: " + url + "\nerror: " + request.error + "\nresponse: " + request.responseCode); yield break; } manifestBundle = DownloadHandlerAssetBundle.GetContent(request); manifest = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); //Continue storeBundleLoader.LoadBundleAndAsset(); }
public void LoadItem(ScriptableStoreItem item) { AssetBundleAssetLoader itemBundleLoader = new AssetBundleAssetLoader(item.bundle); itemBundleLoader.behaviorToRunCoroutines = this; itemBundleLoader.hasShippedVersion = false; itemBundleLoader.autoDownloadNewVersion = true; Hash128 hash = manifest.GetAssetBundleHash(item.bundle.assetBundleName); itemBundleLoader.hardcodedServerBundleHash = hash; itemBundleLoader.useHardcodedHash = true; itemBundleLoader.onAssetLoaded.AddListener((Object asset) => { Debug.Log("Item ready: " + item.descriptiveName + ", asset: " + asset.name); itemsAsset[item.GetThisPlatformId()] = asset; itemsDownloaded[item.GetThisPlatformId()] = true; // Mark it as downloaded right now for consistency onStoreItemReady.Invoke(item, asset); if (state.CurrentState == State.LOADING_DOWNLOADED_ITEMS) { itemsToLoad--; // CHECKING all items downloaded if (itemsToLoad == 0) { SetStoreReady(); } } }); itemBundleLoader.LoadBundleAndAsset(); // can load from cache if available, or download it }
// Use this for initialization protected virtual IEnumerator Start() { if (directLibraryAssetReference != null) { yield return(new WaitForEndOfFrame()); // guarantee all Start methods are called yield return(new WaitForEndOfFrame()); // guarantee all Start methods are called Debug.Log("bypassing bundle loading with a direct reference to a ScriptableLibrary SHIPPED in build."); FetchLibrary(directLibraryAssetReference); } else { assetLoader.state.onStateChanged.AddListener(OnStateChanged); yield return(new WaitForEndOfFrame()); // guarantee all Start methods are called yield return(new WaitForEndOfFrame()); // guarantee all Start methods are called assetLoader.LoadBundleAndAsset(); } }