@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
70 lines (69 loc) • 2.89 kB
TypeScript
/**
* Used to load a group of assets and fires a callback when all assets are loaded.
*
* ```javascript
* const assets = [
* new Asset('model', 'container', { url: `http://example.com/asset.glb` }),
* new Asset('styling', 'css', { url: `http://example.com/asset.css` })
* ];
* const assetListLoader = new AssetListLoader(assets, app.assets);
* assetListLoader.load((err, failed) => {
* if (err) {
* console.error(`${failed.length} assets failed to load`);
* } else {
* console.log(`${assets.length} assets loaded`);
* }
* });
* ```
*
* @category Asset
*/
export class AssetListLoader extends EventHandler {
/**
* Create a new AssetListLoader using a list of assets to load and the asset registry used to load and manage them.
*
* @param {Asset[]|number[]} assetList - An array of {@link Asset} objects to load or an array of Asset IDs to load.
* @param {import('./asset-registry.js').AssetRegistry} assetRegistry - The application's asset registry.
* @example
* const assetListLoader = new pc.AssetListLoader([
* new pc.Asset("texture1", "texture", { url: 'http://example.com/my/assets/here/texture1.png') }),
* new pc.Asset("texture2", "texture", { url: 'http://example.com/my/assets/here/texture2.png') })
* ], app.assets);
*/
constructor(assetList: Asset[] | number[], assetRegistry: import("./asset-registry.js").AssetRegistry);
_assets: Set<any>;
_loadingAssets: Set<any>;
_waitingAssets: Set<any>;
_registry: import("./asset-registry.js").AssetRegistry;
_loading: boolean;
_loaded: boolean;
_failed: any[];
/**
* Removes all references to this asset list loader.
*/
destroy(): void;
_assetHasDependencies(asset: any): any;
/**
* Start loading asset list, call done() when all assets have loaded or failed to load.
*
* @param {Function} done - Callback called when all assets in the list are loaded. Passed (err, failed) where err is the undefined if no errors are encountered and failed contains a list of assets that failed to load.
* @param {object} [scope] - Scope to use when calling callback.
*/
load(done: Function, scope?: object): void;
_callback: Function;
_scope: any;
/**
* Sets a callback which will be called when all assets in the list have been loaded.
*
* @param {Function} done - Callback called when all assets in the list are loaded.
* @param {object} [scope] - Scope to use when calling callback.
*/
ready(done: Function, scope?: object): void;
_loadingComplete(): void;
_onLoad(asset: any): void;
_onError(err: any, asset: any): void;
_onAddAsset(asset: any): void;
_waitForAsset(assetId: any): void;
}
import { EventHandler } from '../../core/event-handler.js';
import { Asset } from './asset.js';