public BundleLoading GetBundleAsyncLoading(string bundleName) { BundleLoading loading = null; this.mBundleAsyncLoadings.TryGetValue(bundleName, out loading); return(loading); }
public BundleLoading NewBundleAsyncLoading(string bundleName) { var loading = new BundleLoading(); this.mBundleAsyncLoadings.Add(bundleName, loading); return(loading); }
private IEnumerator CreateSceneAsync(string sceneName, System.Action <string> handler = null) { this.mIsLoadingScene = true; this.mLoadingSceneName = sceneName; string bundleName = this.GetBundleNameFromLevelName(sceneName); if (string.IsNullOrEmpty(bundleName)) { var oper = SceneManager.LoadSceneAsync(sceneName); yield return(oper); } else { AssetBundle bundle = mBundleCache.Get(bundleName); if (bundle == null) { BundleLoading loading = new BundleLoading(); yield return(this.StartCoroutine(loading.LoadAsync(bundleName))); if (!string.IsNullOrEmpty(loading.error)) { Debug.LogError(loading.error); this.mIsLoadingScene = false; XCSharp.InvokeAction(handler, ""); yield break; } bundle = loading.bundle; } if (bundle == null) { this.mIsLoadingScene = false; XCSharp.InvokeAction(handler, ""); yield break; } var oper = SceneManager.LoadSceneAsync(sceneName); yield return(oper); if (bundle != null) { bundle.Unload(false); } } this.mIsLoadingScene = false; XCSharp.InvokeAction(handler, sceneName); }
public AssetBundle LoadBundle(string bundleName) { AssetBundle bundle = mBundleCache.Get(bundleName); if (bundle != null) { return(bundle); } BundleLoading loading = new BundleLoading(); loading.Load(bundleName); bundle = loading.bundle; mBundleCache.Put(bundleName, bundle); return(bundle); }
private IEnumerator CreateAssetAsync <T>(string bundleName, string location, System.Action <T> handler) where T : Object { // get from cache { T asset = mAssetCache.Get <T>(bundleName, location); if (asset != null) { XCSharp.InvokeAction(handler, asset); yield break; } } // async begins if (mAssetWaitings.Wait(bundleName, location, handler)) { yield break; } string assetPath = bundleName + "/" + location; var req = Resources.LoadAsync <T>(assetPath); yield return(req); if (req.asset != null) { mAssetCache.Put(bundleName, location, req.asset); mAssetWaitings.Notify(location, req.asset as T); yield break; } AssetBundle bundle = mBundleCache.Get(bundleName); if (bundle == null) { BundleLoading loading = mBundleLoader.GetBundleAsyncLoading(bundleName); if (loading != null) { while (!loading.done) { yield return(null); } bundle = loading.bundle; } else { loading = mBundleLoader.NewBundleAsyncLoading(bundleName); yield return(this.StartCoroutine(loading.LoadAsync(bundleName))); if (!string.IsNullOrEmpty(loading.error)) { mAssetWaitings.Notify(location, null as T); yield break; } bundle = loading.bundle; if (bundle != null) { mBundleCache.Put(bundleName, bundle); } } mBundleLoader.RemoveBundleAsyncLoading(bundleName); } if (bundle == null) { mAssetWaitings.Notify(location, null as T); yield break; } { string assetName = System.IO.Path.GetFileName(location); var request = bundle.LoadAssetAsync <T>(assetName); yield return(request); // check if the bundle is destroyed by extern code. if (bundle == null) { mAssetWaitings.Notify(location, null as T); yield break; } // get asset now. if (request.asset != null) { mAssetCache.Put(bundleName, location, request.asset); } mAssetWaitings.Notify(location, request.asset as T); } }