Manage your cookie settings. You can enable or disable different types of cookies below. For more details, see our Privacy Policy.

ResourceManager

1.2.0+

Manager for resources.

Resources are accessed via the engine they belong to.

See: textures, meshes, and materials.

.allocatedCount: number 

Number of textures allocated in the manager.

.count: number 

Number of resources in the manager.

Note: For performance reasons, avoid calling this method when possible.

.engine: WonderlandEngine 

Hosting engine instance.

.all() ⇒ T[] 

1.5.0+

Retrieves non-destroyed resources.

To retrieve resources loaded by a specific scene, use loadedFromScene.

Example 

1// All texture resources currently alive
2const textures = engine.textures.all();
3...
4await engine.textures.create('my.png');
5// `textures` now includes 'my.png'
6const textures = engine.textures.all();

Returns: Array of all resources.

.get(index: number) ⇒ null | T 

Retrieve the resource at the given index.

Note: The index is relative to the host, i.e., doesn’t pack the host index.

ParamTypeDescription
indexnumber

.loadedFromScene(prefab: Prefab) ⇒ T[] 

1.5.0+

Return all resources loaded from a given scene

Note: Resources created at runtime are retrieved using:

1// All textures loaded from the current active scene
2const mainTextures = engine.textures.loadedFromScene(engine.scene);
3
4const prefab = await engine.loadPrefab('Prefab.bin');
5// All textures loaded from the prefab
6const prefabTextures = engine.textures.loadedFromScene(prefab);

Returns: Array of resources loaded from the given prefab.

ParamTypeDescription
prefabPrefabThe prefab

.wrap(index: number) ⇒ null | T 

Wrap the index into a resource instance.

Note: The index is relative to the host, i.e., doesn’t pack the host index (if any).

Returns:

ParamTypeDescription
indexnumberThe resource index.