Common Asset API Reference
Contains functions to load predefined Common Asset groups at mobile runtime.
note
Common Asset API only runs on TikTok phone preview instead of the Effect House preview.
Common Asset List
See the Common Assets for more details.
CommonAssetController
Loads predefined Common Asset groups at mobile runtime.
| Type | Name | Description |
|---|---|---|
| Static Functions | loadAssets(info: CommonAssetControllerRequestInfo, onLoadFinished: () => void): void | Starts a one-time download of the requested remote asset groups
|
| Static Functions | getAssetGroup(groupKey: string): CommonAssetItem[] \| undefined | Returns the assets that succeeded for a group after onLoadFinished
|
| Static Functions | getAsset(groupKey: string, assetKey: string): CommonAssetItem \| null | Returns one asset that succeeded, or null if it is missing or failed to load
|
loadAssets(info: CommonAssetControllerRequestInfo, onLoadFinished: () => void): void
APJS.CommonAssetController.loadAssets(
{
remoteAssetGroupInfos: [
{ groupKey: 'countries', explicitAssetKeys: ['uk', 'usa'] },
{ groupKey: 'food', explicitAssetKeys: ['pizza'], randomAssetCount: 3 },
],
},
() => {
// Read assets only inside this callback.
}
);
getAssetGroup(groupKey: string): CommonAssetItem[] | undefined
const foods = APJS.CommonAssetController.getAssetGroup('food');
if (!foods) {
return;
}
getAsset(groupKey: string, assetKey: string): CommonAssetItem | null
const uk = APJS.CommonAssetController.getAsset('countries', 'uk');
if (uk === null) {
return;
}
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
APJS.CommonAssetController.loadAssets(
{
remoteAssetGroupInfos: [
{
groupKey: 'countries',
explicitAssetKeys: ['uk', 'usa'],
},
{
groupKey: 'food',
explicitAssetKeys: ['pizza'],
randomAssetCount: 3,
},
],
},
() => {
const foods = APJS.CommonAssetController.getAssetGroup('food');
const pizza = APJS.CommonAssetController.getAsset('food', 'pizza');
const uk = APJS.CommonAssetController.getAsset('countries', 'uk');
const texture = uk !== null ? uk.texture : null;
const meta = uk !== null && uk.textData !== null ? JSON.parse(uk.textData) : null;
const ukName = meta !== null ? meta['name'] : null;
const ukCapital = meta !== null ? meta['capital'] : null;
}
);
}
}
CommonAssetControllerRequestInfo
Request payload passed to CommonAssetController.loadAssets.
| Type | Name | Description |
|---|---|---|
| Variables | remoteAssetGroupInfos: CommonAssetGroupRequest[] | The list of remote asset groups to request
|
CommonAssetGroupRequest
One asset group to request during loadAssets.
| Type | Name | Description |
|---|---|---|
| Variables | groupKey: string | The stable key of the asset group to request |
| Variables | explicitAssetKeys?: string[] | Exact asset keys to request
|
| Variables | randomAssetCount?: number | Number of random assets to request
|
CommonAssetItem
One loaded common asset returned by getAssetGroup or getAsset.
| Type | Name | Description |
|---|---|---|
| Variables | groupKey: string | The asset group that contains this item |
| Variables | assetKey: string | The stable key of this asset |
| Variables | texture: Texture \| null | The loaded texture for downloaded media assets
|
| Variables | textData: string \| null | JSON object string for this asset's metadata
|