/// <summary> /// Reloads the specified asset. /// </summary> /// <param name="assetName">Name of the asset to load</param> /// <returns>The new reference to the reloaded asset</returns> public object Reload(string assetName, AssetLoadedHandler Callback) { if (mCache.ContainsKey(assetName)) { AssetTracker oldAssetTracker = mCache[assetName]; // Remove tracker so Load<T>() will create a new one mCache.Remove(assetName); mCacheNames.Remove(assetName); // Load it again object asset = Load(assetName, Callback); // Invoke AssetChanged event oldAssetTracker.OnAssetChanged(new AssetChangedEventArgs(asset)); // Destroy previous tracker DisposeAssetTracker(oldAssetTracker, true); return(asset); } else { return(Load(assetName, Callback)); } }
private AssetRequest <TAsset> loadAsync <TAsset>(string key, AssetLoadedHandler <TAsset> handler = null) where TAsset : class { ContentManifest.AssetEntry entry = getAssetEntry(key); TAsset indexedAsset = getIndexedAsset <TAsset>(entry.Key); AssetRequest <TAsset> assetRequest; CoroutineReturn value; if (indexedAsset != null) { assetRequest = new IndexedAssetRequest <TAsset>(entry.Key, indexedAsset); if (handler != null) { CoroutineRunner.StartPersistent(waitOneFrameBeforeCallingHandler(key, indexedAsset, handler), this, "waitOneFrameBeforeCallingHandler"); } } else if (!activeRequests.TryGetValue(entry.Key, out value)) { activeRequestHandlers.Add(entry.Key, new List <object>()); assetRequest = loadAsyncEntry(ref entry, handler); activeRequests.Add(entry.Key, assetRequest); } else { if (handler != null) { activeRequestHandlers[entry.Key].Add(handler); } assetRequest = (AssetRequest <TAsset>)value; } if (assetRequest == null) { Log.LogError(this, "Failed to load " + key); } return(assetRequest); }
/// <summary> /// Return the specified asset arrays. Read it from disk if not available /// </summary> /// <typeparam name="T">The Type of asset to load</typeparam> /// <param name="assetNames">Names of the assets to load</param> /// <returns>A reference array to the loaded assets</returns> public object[] Load(string[] assetNames, AssetLoadedHandler Callback) { object[] assets = new object[assetNames.Length]; for (int i = 0; i < assets.Length; i++) { assets[i] = Load(assetNames[i], null, Callback); } return(assets); }
/// <summary> /// Asyncronously loads the specified asset /// </summary> /// <param name="assetName">Name of asset to laod</param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <returns>AssetTracker of asset to be loaded. Allows to poll the asset status if desired</returns> public AssetTracker LoadAsync(string assetName, AssetLoaded itemLoadedMethod, AssetLoadedHandler Callback) { AssetTracker tracker = null; // Check if asset is already loaded if (mCache.ContainsKey(assetName)) { tracker = mCache[assetName]; // Increment reference count tracker.RefCount++; // Call the specified item loaded method if (itemLoadedMethod != null) itemLoadedMethod(tracker.Asset); } else { if (mLoadThread == null) { // First time LoadAsync has been called so // initialise thread, reset event and queue mLoadThread = new Thread(new ThreadStart(LoadingThreadWorker)); mLoadItemsQueue = new Queue<LoadAsyncParams>(); mLoadResetEvent = new AutoResetEvent(false); // Start thread. It will wait once queue is empty mLoadThread.Start(); } // Create the async argument structure and enqueue it for async load. lock (mLoadItemsQueue) { // first check if this item is already enqueued Queue<LoadAsyncParams>.Enumerator enumer = mLoadItemsQueue.GetEnumerator(); while (enumer.MoveNext()) { if (enumer.Current.Tracker.AssetName == assetName) { // Register the itemLoaded method enumer.Current.ItemLoadedMethods.Add(itemLoadedMethod); tracker = enumer.Current.Tracker; tracker.RefCount++; break; } } // Item not already queued for loading if (tracker == null) { LoadAsyncParams args = new LoadAsyncParams(assetName, itemLoadedMethod); tracker = args.Tracker; mLoadItemsQueue.Enqueue(args); } } // Tell loading thread to stop waiting mLoadResetEvent.Set(); } tracker.OnAssetLoaded = Callback; // Return tracker. Allows async caller to poll loaded status return tracker; }
public static bool TryLoadAsync <TAsset>(out AssetRequest <TAsset> result, AssetLoadedHandler <TAsset> handler, TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class { string key2 = key.Expand(args); if (ContainsKey(key2)) { result = LoadAsync(key2, handler); return(true); } result = null; return(false); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { Resources.Load <TextAsset>(entry.Key); ResourceRequest unityRequest = Resources.LoadAsync <TextAsset>(entry.Key); AssetRequestWrapper <TAsset> request = new AssetRequestWrapper <TAsset>(null); AsyncAssetRequest <TAsset> asyncAssetRequest = new AsyncAssetRequest <TAsset>(entry.Key, request); CoroutineRunner.StartPersistent(waitForTextAssetToLoad(entry.Key, unityRequest, asyncAssetRequest), this, "test"); return(asyncAssetRequest); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { string key = entry.Key; TextAsset textAsset = Resources.Load <TextAsset>(key); return(new IndexedAssetRequest <TAsset>(entry.Key, (TAsset)(object)textAsset)); }
/// <summary> /// Return the specified asset arrays. Read it from disk if not available /// </summary> /// <param name="filenames">Names of the assets to load</param> /// <param name="callback"></param> /// <returns>A reference array to the loaded assets</returns> public object[] Load(string[] filenames, AssetLoadedHandler callback) { return(mExtendedContentManager.Load(filenames, callback)); }
/// <summary> /// Return the specified asset List. Read it from disk if not available /// </summary> /// <param name="filenames"></param> /// <param name="callback"></param> /// <returns>A reference List to the loaded assets</returns> public List <object> Load(List <string> filenames, AssetLoadedHandler callback) { return(mExtendedContentManager.Load(filenames, callback)); }
private IEnumerator waitForFileStreamAssetToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class { FileStream fileStream = new FileStream(key, FileMode.Open, FileAccess.Read, FileShare.Read, 1024, useAsync: true); byte[] bytes; try { bytes = new byte[fileStream.Length]; IAsyncResult asyncResult = fileStream.BeginRead(bytes, 0, bytes.Length, null, null); while (!asyncResult.IsCompleted) { yield return(null); } fileStream.EndRead(asyncResult); } finally { fileStream.Close(); } assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)bytes); yield return(assetRequest); handler?.Invoke(key, (TAsset)(object)bytes); }
private IEnumerator waitForBundleToCreate <TAsset>(string key, AssetBundleCreateWrapper bundleRequest, AssetLoadedHandler <TAsset> handler) where TAsset : class { AssetBundleCreateRequest bundleLoadRequest = (AssetBundleCreateRequest)(bundleRequest.MutableOperation = AssetBundle.LoadFromFileAsync(key)); yield return(bundleLoadRequest); AssetBundle bundle = bundleLoadRequest.assetBundle; if (bundle == null) { Log.LogError(this, "Failed to load asset bundle:" + key); } }
/// <summary> /// Asyncronously loads the specified asset array /// </summary> /// <param name="assetNames">Names of assets to laod</param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <returns>AssetTracker array of assets to be loaded. Allows to poll the asset status if desired</returns> public AssetTracker[] LoadAsync(string[] assetNames, AssetLoaded itemLoadedMethod, AssetLoadedHandler Callback) { AssetTracker[] assets = new AssetTracker[assetNames.Length]; for (int i = 0; i < assets.Length; i++) assets[i] = LoadAsync(assetNames[i], itemLoadedMethod, Callback); return assets; }
/// <summary> /// Reloads the specified asset. /// </summary> /// <param name="assetName">Name of the asset to load</param> /// <returns>The new reference to the reloaded asset</returns> public object Reload( string assetName, AssetLoadedHandler Callback ) { if( mCache.ContainsKey( assetName ) ) { AssetTracker oldAssetTracker = mCache[ assetName ]; // Remove tracker so Load<T>() will create a new one mCache.Remove( assetName ); mCacheNames.Remove( assetName ); // Load it again object asset = Load( assetName, Callback ); // Invoke AssetChanged event oldAssetTracker.OnAssetChanged( new AssetChangedEventArgs( asset ) ); // Destroy previous tracker DisposeAssetTracker( oldAssetTracker, true ); return asset; } else return Load( assetName, Callback ); }
public AsyncAssetBundleRequest <TAsset> LoadAsync <TAsset>(string key, string assetPath, AssetLoadedHandler <TAsset> handler = null) where TAsset : class { AsyncAssetBundleRequest <TAsset> asyncAssetBundleRequest; if (activeRequests.TryGetValue(key, out var value)) { asyncAssetBundleRequest = (AsyncAssetBundleRequest <TAsset>)value; } else { asyncAssetBundleRequest = new AsyncAssetBundleRequest <TAsset>(key, null); activeRequests[key] = asyncAssetBundleRequest; CoroutineRunner.StartPersistent(waitForAssetToLoad(key, assetPath, asyncAssetBundleRequest, handler), this, "waitForAssetToLoad"); } LastLoadFrame = Time.frameCount; return(asyncAssetBundleRequest); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { return(AsycnResourceLoader <TAsset> .Load(ref entry, handler)); }
public static AssetRequest <TAsset> Load(ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { ResourceRequest resourceRequest = Resources.LoadAsync(entry.Key, typeof(TAsset)); if (resourceRequest.isDone && resourceRequest.asset == null) { throw new ArgumentException("Asset could not be loaded. Is the key correct? Key = " + entry.Key); } AsyncAssetResourceRequest <TAsset> asyncAssetResourceRequest = new AsyncAssetResourceRequest <TAsset>(entry.Key, resourceRequest); if (handler != null) { CoroutineRunner.StartPersistent(waitForLoadToFinish(entry.Key, asyncAssetResourceRequest, handler), typeof(AsycnResourceLoader <TAsset>), "waitForLoadToFinish"); } return(asyncAssetResourceRequest); }
private object Load( string assetName, AssetTracker tracker, AssetLoadedHandler Callback ) { // Return asset if currently loaded if( mCache.ContainsKey( assetName ) ) { // Get asset tracker AssetTracker trackerExisting = mCache[ assetName ]; object asset = trackerExisting.Asset; // Increment tracker's reference count after the cast as the cast will // throw an exception if the incorrect generic type parameter is given trackerExisting.RefCount++; // Maintain the reference lists to show that this asset was loaded by // the asset on the top of the stack if( mCacheLoadingStack.Count > 0 ) { mCacheLoadingStack.Peek().RefersTo.Add( assetName ); trackerExisting.ReferredToBy.Add( mCacheLoadingStack.Peek().AssetName ); } return asset; } // Need to load the asset. Create an AssetTracker to track it // unless we have been passed an existing AssetTracker if( tracker == null ) { // Initialise tracker tracker = new AssetTracker(); tracker.RefCount = 1; tracker.AssetName = assetName; } // Stack count will be zero if called by user. // Otherwise, Load<T> was called internally by ReadAsset<T> if( mCacheLoadingStack.Count > 0 ) { // Maintain the reference lists // The asset on the top of the stack refers to this asset mCacheLoadingStack.Peek().RefersTo.Add( assetName ); // This asset was loaded by the asset on the top of the stack tracker.ReferredToBy.Add( mCacheLoadingStack.Peek().AssetName ); } // Put current asset tracker on top of the stack // for next call to Load<T> mCacheLoadingStack.Push( tracker ); try { tracker.Asset = ReadAsset( assetName, tracker.TrackDisposableAsset ); tracker.Asset = Callback( tracker ); // Ensure the list of disposables doesn't refer to the // actual asset, or to any assets in the loadedAssets Dictionary. // Best to do this now to avoid multiple disposing later tracker.Disposables.RemoveAll( delegate( IDisposable d ) { string tmp = ""; return tracker.Asset == d || SearchForAsset( d, out tmp ); } ); } catch( Exception ex ) { System.Diagnostics.Debug.WriteLine( "Asset.Load() Exception\n" + ex.ToString() ); } finally { // Asset has been loaded so the top tracker is not needed on the stack mCacheLoadingStack.Pop(); } // Store the asset and it's disposables list mCache.Add( assetName, tracker ); mCacheNames.Add( assetName ); // Mark tracker as ready to use tracker.Status = EAssetStatus.Active; // Return loaded asset return tracker.Asset; }
/// <summary> /// Return the specified asset. Read it from disk if not available /// </summary> /// <typeparam name="T">The Type of asset to load</typeparam> /// <param name="assetName">Name of the asset to load</param> /// <returns>A reference to the loaded asset</returns> public object Load( string assetName, AssetLoadedHandler Callback ) { return Load( assetName, null, Callback ); }
/// <summary> /// Return the specified asset List. Read it from disk if not available /// </summary> /// <typeparam name="T">The Type of asset to load</typeparam> /// <param name="assetNames">Names of the assets to load</param> /// <returns>A reference List to the loaded assets</returns> public List<object> Load( List<string> assetNames, AssetLoadedHandler Callback ) { return new List<object>( this.Load( assetNames.ToArray(), Callback ) ); }
/// <summary> /// Return the specified asset arrays. Read it from disk if not available /// </summary> /// <typeparam name="T">The Type of asset to load</typeparam> /// <param name="assetNames">Names of the assets to load</param> /// <returns>A reference array to the loaded assets</returns> public object[] Load( string[] assetNames, AssetLoadedHandler Callback ) { object[] assets = new object[ assetNames.Length ]; for( int i = 0; i < assets.Length; i++ ) assets[ i ] = Load( assetNames[ i ], null, Callback ); return assets; }
private IEnumerator waitForStringToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, AssetRequest <TextAsset> textRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class { yield return(textRequest); string text = textRequest.Asset.text; assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)text); yield return(assetRequest); handler?.Invoke(key, (TAsset)(object)text); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { string bundlePath = UriUtil.Combine(baseUri, entry.Key); AssetBundleWwwWrapper assetBundleWwwWrapper = new AssetBundleWwwWrapper(bundlePath, gcsAccessTokenService); AsyncBundleWwwRequest <TAsset> result = new AsyncBundleWwwRequest <TAsset>(entry.Key, assetBundleWwwWrapper); uint result2 = 0u; if (entry.UserData != null && entry.UserData is ContentManifest.BundleEntry && !uint.TryParse(((ContentManifest.BundleEntry)entry.UserData).Crc, out result2)) { result2 = 0u; } CoroutineRunner.StartPersistent(waitForBundleToLoad(assetBundleWwwWrapper, result2, handler), this, "waitForBundleToLoad"); return(result); }
private IEnumerator waitForFileStreamAssetToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class { string fileText; using (StreamReader streamReader = new StreamReader(key)) { fileText = streamReader.ReadToEnd(); } assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)fileText); yield return(assetRequest); handler?.Invoke(key, (TAsset)(object)fileText); }
private IEnumerator waitForBundleToLoad <TAsset>(AssetBundleWwwWrapper bundleRequestWrapper, uint crc, AssetLoadedHandler <TAsset> handler) where TAsset : class { CPipeManifestResponse cpipeManifestResponse = new CPipeManifestResponse(); yield return(cpipeManifestService.LookupAssetUrl(cpipeManifestResponse, bundleRequestWrapper.BundlePath)); if (string.IsNullOrEmpty(cpipeManifestResponse.FullAssetUrl)) { throw new Exception($"Bundle \"{bundleRequestWrapper.BundlePath}\" NOT FOUND in CPipe manifest."); } while (!Caching.ready) { yield return(null); } bundleRequestWrapper.LoadFromCacheOrDownload(cpipeManifestResponse.FullAssetUrl, crc); Service.Get <LoadingController>().RegisterDownload(bundleRequestWrapper.WebRequest); yield return(bundleRequestWrapper.Send()); Service.Get <LoadingController>().UnRegisterDownload(bundleRequestWrapper.WebRequest); if (DelayLoading) { yield return(null); yield return(null); } for (int i = 0; i < 3; i++) { if (bundleRequestWrapper.WebRequest.isNetworkError) { Log.LogErrorFormatted(this, "Retry count {0}. Failed to download bundle {1} with error: {2}", i + 1, bundleRequestWrapper.BundlePath, bundleRequestWrapper.WebRequest.error); } else { if (!(bundleRequestWrapper.AssetBundle == null)) { break; } Log.LogErrorFormatted(this, "Retry count {0}. Downloaded bundle was null", i + 1); } bundleRequestWrapper.LoadFromCacheOrDownload(cpipeManifestResponse.FullAssetUrl, crc); string message = $"Retry bundle load with expected CRC {crc}: {bundleRequestWrapper.BundlePath}"; Crittercism.LeaveBreadcrumb(message); Service.Get <LoadingController>().RegisterDownload(bundleRequestWrapper.WebRequest); yield return(bundleRequestWrapper.Send()); Service.Get <LoadingController>().UnRegisterDownload(bundleRequestWrapper.WebRequest); } if (bundleRequestWrapper.AssetBundle != null) { string breadcrumb = $"Loaded bundle with expected CRC {crc}: {bundleRequestWrapper.BundlePath}"; Crittercism.LeaveBreadcrumb(breadcrumb); } else { string breadcrumb = $"Failed to load bundle with expected CRC {crc}: {bundleRequestWrapper.BundlePath}"; Crittercism.LeaveBreadcrumb(breadcrumb); } if (handler != null) { TAsset asset = null; if (bundleRequestWrapper.AssetBundle != null) { asset = (TAsset)(object)bundleRequestWrapper.AssetBundle; } handler(bundleRequestWrapper.BundlePath, asset); } bundleRequestWrapper.IsComplete = true; bundleRequestWrapper.CacheAndDispose(); }
/// <summary> /// Asyncronously loads the specified asset List /// </summary> /// <param name="assetNames">Names of assets to laod</param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <returns>AssetTracker List of assets to be loaded. Allows to poll the asset status if desired</returns> public List<AssetTracker> LoadAsync(List<string> assetNames, AssetLoaded itemLoadedMethod, AssetLoadedHandler Callback) { return new List<AssetTracker>(LoadAsync(assetNames.ToArray(), itemLoadedMethod, Callback)); }
/// <summary> /// Asyncronously loads the specified asset array /// </summary> /// <param name="assetNames">Names of assets to laod</param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <returns>AssetTracker array of assets to be loaded. Allows to poll the asset status if desired</returns> public AssetTracker[] LoadAsync(string[] assetNames, AssetLoaded itemLoadedMethod, AssetLoadedHandler Callback) { AssetTracker[] assets = new AssetTracker[assetNames.Length]; for (int i = 0; i < assets.Length; i++) { assets[i] = LoadAsync(assetNames[i], itemLoadedMethod, Callback); } return(assets); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { AssetRequestWrapper <TAsset> request = new AssetRequestWrapper <TAsset>(null); AsyncAssetRequest <TAsset> asyncAssetRequest = new AsyncAssetRequest <TAsset>(entry.Key, request); CoroutineRunner.StartPersistent(waitForFileStreamAssetToLoad(asyncAssetRequest, entry.AssetPath, handler), this, "waitForFileStreamAssetToLoad"); return(asyncAssetRequest); }
/// <summary> /// Asyncronously loads the specified asset List /// </summary> /// <param name="assetNames">Names of assets to laod</param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <returns>AssetTracker List of assets to be loaded. Allows to poll the asset status if desired</returns> public List <AssetTracker> LoadAsync(List <string> assetNames, AssetLoaded itemLoadedMethod, AssetLoadedHandler Callback) { return(new List <AssetTracker>(LoadAsync(assetNames.ToArray(), itemLoadedMethod, Callback))); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { AssetBundleCreateWrapper assetBundleCreateWrapper = new AssetBundleCreateWrapper(null); AsyncBundleCreateRequest <TAsset> result = new AsyncBundleCreateRequest <TAsset>(entry.Key, assetBundleCreateWrapper); CoroutineRunner.StartPersistent(waitForBundleToCreate(entry.Key, assetBundleCreateWrapper, handler), this, "waitForBundleToCreate"); return(result); }
/// <summary> /// Asyncronously loads the specified asset /// </summary> /// <param name="assetName">Name of asset to laod</param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <returns>AssetTracker of asset to be loaded. Allows to poll the asset status if desired</returns> public AssetTracker LoadAsync(string assetName, AssetLoaded itemLoadedMethod, AssetLoadedHandler Callback) { AssetTracker tracker = null; // Check if asset is already loaded if (mCache.ContainsKey(assetName)) { tracker = mCache[assetName]; // Increment reference count tracker.RefCount++; // Call the specified item loaded method if (itemLoadedMethod != null) { itemLoadedMethod(tracker.Asset); } } else { if (mLoadThread == null) { // First time LoadAsync has been called so // initialise thread, reset event and queue mLoadThread = new Thread(new ThreadStart(LoadingThreadWorker)); mLoadItemsQueue = new Queue <LoadAsyncParams>(); mLoadResetEvent = new AutoResetEvent(false); // Start thread. It will wait once queue is empty mLoadThread.Start(); } // Create the async argument structure and enqueue it for async load. lock (mLoadItemsQueue) { // first check if this item is already enqueued Queue <LoadAsyncParams> .Enumerator enumer = mLoadItemsQueue.GetEnumerator(); while (enumer.MoveNext()) { if (enumer.Current.Tracker.AssetName == assetName) { // Register the itemLoaded method enumer.Current.ItemLoadedMethods.Add(itemLoadedMethod); tracker = enumer.Current.Tracker; tracker.RefCount++; break; } } // Item not already queued for loading if (tracker == null) { LoadAsyncParams args = new LoadAsyncParams(assetName, itemLoadedMethod); tracker = args.Tracker; mLoadItemsQueue.Enqueue(args); } } // Tell loading thread to stop waiting mLoadResetEvent.Set(); } tracker.OnAssetLoaded = Callback; // Return tracker. Allows async caller to poll loaded status return(tracker); }
/// <summary> /// Asyncronously loads the specified asset List /// </summary> /// <param name="filenames"></param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <param name="callback"></param> /// <returns>AssetTracker List of assets to be loaded. Allows to poll the asset status if desired</returns> public List <AssetTracker> LoadAsync(List <string> filenames, AssetLoaded itemLoadedMethod, AssetLoadedHandler callback) { return(mExtendedContentManager.LoadAsync(filenames, itemLoadedMethod, callback)); }
public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) { gcsAccessTokenService = Service.Get <IGcsAccessTokenService>(); string bundlePath = UriUtil.Combine(baseUri, entry.Key); AssetBundleWwwWrapper assetBundleWwwWrapper = new AssetBundleWwwWrapper(bundlePath, gcsAccessTokenService); AsyncBundleWwwRequest <TAsset> result = new AsyncBundleWwwRequest <TAsset>(entry.Key, assetBundleWwwWrapper); CoroutineRunner.StartPersistent(waitForBundleToLoad(assetBundleWwwWrapper, handler, entry.IsCacheOnly), this, "Local_waitForBundleToLoad"); return(result); }
/// <summary> /// Asyncronously loads the specified asset array /// </summary> /// <param name="filenames"></param> /// <param name="itemLoadedMethod">Method to call once load is completed</param> /// <param name="callback"></param> /// <returns>AssetTracker array of assets to be loaded. Allows to poll the asset status if desired</returns> public AssetTracker[] LoadAsync(string[] filenames, AssetLoaded itemLoadedMethod, AssetLoadedHandler callback) { return(mExtendedContentManager.LoadAsync(filenames, itemLoadedMethod, callback)); }
private IEnumerator waitForBundleToLoad <TAsset>(AssetBundleWwwWrapper bundleRequest, AssetLoadedHandler <TAsset> handler, bool cacheOnly) where TAsset : class { bundleRequest.LoadFromDownload(bundleRequest.BundlePath); Service.Get <LoadingController>().RegisterDownload(bundleRequest.WebRequest); yield return(bundleRequest.Send()); Service.Get <LoadingController>().UnRegisterDownload(bundleRequest.WebRequest); if (handler != null) { AssetBundle assetBundle = null; if (!cacheOnly) { assetBundle = bundleRequest.AssetBundle; } TAsset asset = null; if (assetBundle != null) { asset = (TAsset)(object)assetBundle; } handler(bundleRequest.BundlePath, asset); } yield return(null); }
public AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) where TAsset : class { prepareDevice(ref deviceList, out var device); return(device.LoadAsync(deviceList, ref entry, handler)); }
private IEnumerator waitForStringToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, AssetRequest <string> stringRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class { yield return(stringRequest); string jsonString = stringRequest.Asset; JsonService json = Service.Get <JsonService>(); TAsset jsonAsset = json.Deserialize <TAsset>(jsonString); assetRequest.Request = new IndexedAssetRequest <TAsset>(key, jsonAsset); handler?.Invoke(key, jsonAsset); }
public abstract AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) where TAsset : class;
private IEnumerator waitForAssetToLoad <TAsset>(string key, string assetPath, AsyncAssetBundleRequest <TAsset> assetRequest, AssetLoadedHandler <TAsset> handler) where TAsset : class { AssetBundleRequest unityRequest = (assetRequest.Request = Bundle.LoadAssetAsync <TAsset>(assetPath)); yield return(unityRequest); activeRequests.Remove(key); handler?.Invoke(key, (TAsset)(object)unityRequest.asset); if (this.EFinishedLoading != null && activeRequests.Count == 0) { yield return(null); this.EFinishedLoading(); } }