public IEnumerator InstantiateObjectAsync(AssetsTableScriptableObject.AssetEntry assetEntry, System.Action <Object> callback) { if (string.IsNullOrEmpty(assetEntry.AssetBundleName) || string.IsNullOrEmpty(assetEntry.AssetName)) { if (assetEntry.DefaultAssetRef != null) { callback(Instantiate(assetEntry.DefaultAssetRef)); } yield break; } AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetEntry.AssetBundleName, assetEntry.AssetName, typeof(Object)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. Object prefab = request.GetAsset <Object>(); if (prefab != null) { callback(Instantiate(prefab)); } else { callback(null); } }
public void LoadLevel(ref AssetsTableScriptableObject.AssetEntry assetEntry) { if (string.IsNullOrEmpty(assetEntry.AssetBundleName) || string.IsNullOrEmpty(assetEntry.AssetName)) { if (assetEntry.DefaultAssetText != null) { SceneManager.LoadSceneAsync(assetEntry.DefaultAssetText); } } else { StartCoroutine(InitializeLevelAsync(assetEntry)); } }
protected IEnumerator InitializeLevelAsync(AssetsTableScriptableObject.AssetEntry assetEntry, bool isAdditive = false) { //float startTime = Time.realtimeSinceStartup; AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(assetEntry.AssetBundleName, assetEntry.AssetName, isAdditive); if (request == null) { yield break; } yield return(StartCoroutine(request)); //Calculate and display the elapsed time. //float elapsedTime = Time.realtimeSinceStartup - startTime; //Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds"); }
private IEnumerator DownLoadManifestAndInitAssetBundleManager(AssetBundleUpdateInfo updateInfo) { yield return(StartCoroutine(AssetsLoader.DownloadManifest(updateInfo))); #if UNITY_EDITOR // If we're in Editor simulation mode, we don't need the manifest assetBundle. if (!AssetBundleManager.SimulateAssetBundleInEditor) #endif { if (AssetBundleManager.AssetBundleManifestObject != null) { yield return(StartCoroutine(AssetsLoader.Instance.DownLoadAllAssetBundlesAsync())); } else { GlobalBehaviors.Instance.AddAMessageBox("Error", "You can't load game content index correctly :( Please try restart the game!", MessageBoxType.YES, "OK", null, null, null, null, null); //no way ... yield break; } } //load assets table first AssetsTableScriptableObject assetsTableObj; AssetsTableScriptableObject.AssetEntry assetsTableEntry = new AssetsTableScriptableObject.AssetEntry();//fake entry :D assetsTableEntry.AssetBundleName = "assetstable"; assetsTableEntry.AssetName = "assetsTable"; yield return(StartCoroutine(AssetsLoader.Instance.InstantiateObjectAsync(assetsTableEntry, (newAssetstable) => { if (newAssetstable != null) { assetsTableObj = newAssetstable as AssetsTableScriptableObject; if (assetsTableObj != null) { AssetsLoader.Instance.SetDownloadedAssetsTableObj(assetsTableObj); } } }))); EventManager.TriggerEvent(new EventObj("AssetBundlesDownloaded")); }