public class AssetManager extends java.lang.Object implements Disposable
Constructor and Description |
---|
AssetManager()
Creates a new AssetManager with all default loaders.
|
AssetManager(FileHandleResolver resolver)
Creates a new AssetManager with all default loaders.
|
AssetManager(FileHandleResolver resolver,
boolean defaultLoaders)
Creates a new AssetManager with optionally all default loaders.
|
Modifier and Type | Method and Description |
---|---|
protected <T> void |
addAsset(java.lang.String fileName,
java.lang.Class<T> type,
T asset)
Adds an asset to this AssetManager
|
void |
clear()
Clears and disposes all assets and the preloading queue.
|
boolean |
contains(java.lang.String fileName)
Returns true if an asset with the specified name is loading, queued to be loaded, or has been loaded.
|
boolean |
contains(java.lang.String fileName,
java.lang.Class type)
Returns true if an asset with the specified name and type is loading, queued to be loaded, or has been loaded.
|
<T> boolean |
containsAsset(T asset) |
void |
dispose()
Disposes all assets in the manager and stops all asynchronous loading.
|
void |
finishLoading()
Blocks until all assets are loaded.
|
<T> T |
finishLoadingAsset(AssetDescriptor assetDesc)
Blocks until the specified asset is loaded.
|
<T> T |
finishLoadingAsset(java.lang.String fileName)
Blocks until the specified asset is loaded.
|
<T> T |
get(AssetDescriptor<T> assetDescriptor) |
<T> T |
get(java.lang.String fileName) |
<T> T |
get(java.lang.String fileName,
java.lang.Class<T> type) |
<T> Array<T> |
getAll(java.lang.Class<T> type,
Array<T> out) |
<T> java.lang.String |
getAssetFileName(T asset) |
Array<java.lang.String> |
getAssetNames() |
java.lang.Class |
getAssetType(java.lang.String fileName) |
Array<java.lang.String> |
getDependencies(java.lang.String fileName) |
java.lang.String |
getDiagnostics() |
FileHandleResolver |
getFileHandleResolver()
Returns the
FileHandleResolver for which this AssetManager was loaded with. |
int |
getLoadedAssets() |
<T> AssetLoader |
getLoader(java.lang.Class<T> type)
Returns the default loader for the given type.
|
<T> AssetLoader |
getLoader(java.lang.Class<T> type,
java.lang.String fileName)
Returns the loader for the given type and the specified filename.
|
Logger |
getLogger() |
float |
getProgress() |
int |
getQueuedAssets() |
int |
getReferenceCount(java.lang.String fileName)
Returns the reference count of an asset.
|
boolean |
isFinished()
Returns true when all assets are loaded.
|
boolean |
isLoaded(AssetDescriptor assetDesc) |
boolean |
isLoaded(java.lang.String fileName) |
boolean |
isLoaded(java.lang.String fileName,
java.lang.Class type) |
void |
load(AssetDescriptor desc)
Adds the given asset to the loading queue of the AssetManager.
|
<T> void |
load(java.lang.String fileName,
java.lang.Class<T> type)
Adds the given asset to the loading queue of the AssetManager.
|
<T> void |
load(java.lang.String fileName,
java.lang.Class<T> type,
AssetLoaderParameters<T> parameter)
Adds the given asset to the loading queue of the AssetManager.
|
void |
setErrorListener(AssetErrorListener listener)
Sets an
AssetErrorListener to be invoked in case loading an asset failed. |
<T,P extends AssetLoaderParameters<T>> |
setLoader(java.lang.Class<T> type,
AssetLoader<T,P> loader)
Sets a new
AssetLoader for the given type. |
<T,P extends AssetLoaderParameters<T>> |
setLoader(java.lang.Class<T> type,
java.lang.String suffix,
AssetLoader<T,P> loader)
Sets a new
AssetLoader for the given type. |
void |
setLogger(Logger logger) |
void |
setReferenceCount(java.lang.String fileName,
int refCount)
Sets the reference count of an asset.
|
protected void |
taskFailed(AssetDescriptor assetDesc,
java.lang.RuntimeException ex)
Called when a task throws an exception during loading.
|
void |
unload(java.lang.String fileName)
Removes the asset and all its dependencies, if they are not used by other assets.
|
boolean |
update()
Updates the AssetManager for a single task.
|
boolean |
update(int millis)
Updates the AssetManager continuously for the specified number of milliseconds, yielding the CPU to the loading thread
between updates.
|
public AssetManager()
public AssetManager(FileHandleResolver resolver)
public AssetManager(FileHandleResolver resolver, boolean defaultLoaders)
defaultLoaders
- whether to add the default loaderspublic FileHandleResolver getFileHandleResolver()
FileHandleResolver
for which this AssetManager was loaded with.public <T> T get(java.lang.String fileName)
fileName
- the asset file namepublic <T> T get(java.lang.String fileName, java.lang.Class<T> type)
fileName
- the asset file nametype
- the asset typepublic <T> Array<T> getAll(java.lang.Class<T> type, Array<T> out)
type
- the asset typepublic <T> T get(AssetDescriptor<T> assetDescriptor)
assetDescriptor
- the asset descriptorpublic boolean contains(java.lang.String fileName)
public boolean contains(java.lang.String fileName, java.lang.Class type)
public void unload(java.lang.String fileName)
fileName
- the file namepublic <T> boolean containsAsset(T asset)
asset
- the assetpublic <T> java.lang.String getAssetFileName(T asset)
asset
- the assetpublic boolean isLoaded(AssetDescriptor assetDesc)
assetDesc
- the AssetDescriptor of the assetpublic boolean isLoaded(java.lang.String fileName)
fileName
- the file name of the assetpublic boolean isLoaded(java.lang.String fileName, java.lang.Class type)
fileName
- the file name of the assetpublic <T> AssetLoader getLoader(java.lang.Class<T> type)
type
- The type of the loader to getpublic <T> AssetLoader getLoader(java.lang.Class<T> type, java.lang.String fileName)
type
- The type of the loader to getfileName
- The filename of the asset to get a loader for, or null to get the default loaderpublic <T> void load(java.lang.String fileName, java.lang.Class<T> type)
fileName
- the file name (interpretation depends on AssetLoader
)type
- the type of the asset.public <T> void load(java.lang.String fileName, java.lang.Class<T> type, AssetLoaderParameters<T> parameter)
fileName
- the file name (interpretation depends on AssetLoader
)type
- the type of the asset.parameter
- parameters for the AssetLoader.public void load(AssetDescriptor desc)
desc
- the AssetDescriptor
public boolean update()
public boolean update(int millis)
public boolean isFinished()
update()
or related methods must
be called to process tasks.public void finishLoading()
public <T> T finishLoadingAsset(AssetDescriptor assetDesc)
assetDesc
- the AssetDescriptor of the assetpublic <T> T finishLoadingAsset(java.lang.String fileName)
fileName
- the file name (interpretation depends on AssetLoader
)protected <T> void addAsset(java.lang.String fileName, java.lang.Class<T> type, T asset)
protected void taskFailed(AssetDescriptor assetDesc, java.lang.RuntimeException ex)
public <T,P extends AssetLoaderParameters<T>> void setLoader(java.lang.Class<T> type, AssetLoader<T,P> loader)
AssetLoader
for the given type.type
- the type of the assetloader
- the loaderpublic <T,P extends AssetLoaderParameters<T>> void setLoader(java.lang.Class<T> type, java.lang.String suffix, AssetLoader<T,P> loader)
AssetLoader
for the given type.type
- the type of the assetsuffix
- the suffix the filename must have for this loader to be used or null to specify the default loader.loader
- the loaderpublic int getLoadedAssets()
public int getQueuedAssets()
public float getProgress()
public void setErrorListener(AssetErrorListener listener)
AssetErrorListener
to be invoked in case loading an asset failed.listener
- the listener or nullpublic void dispose()
dispose
in interface Disposable
public void clear()
public Logger getLogger()
Logger
used by the AssetManager
public void setLogger(Logger logger)
public int getReferenceCount(java.lang.String fileName)
fileName
- public void setReferenceCount(java.lang.String fileName, int refCount)
fileName
- public java.lang.String getDiagnostics()
public Array<java.lang.String> getAssetNames()
public Array<java.lang.String> getDependencies(java.lang.String fileName)
public java.lang.Class getAssetType(java.lang.String fileName)