Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mypackage;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.utils.Array;
- import com.badlogic.gdx.utils.reflect.ClassReflection;
- import com.badlogic.gdx.utils.reflect.Field;
- import com.badlogic.gdx.utils.reflect.ReflectionException;
- import net.dermetfan.gdx.assets.AnnotationAssetManager;
- import net.dermetfan.gdx.assets.AnnotationAssetManager.Asset;
- public class Assetz {
- public static final AnnotationAssetManager manager = new AnnotationAssetManager();
- @Asset(Texture.class)
- public static final LoadItem ball = new LoadItem("img/ball.png", true);
- private static class LoadItem {
- private String path;
- private boolean remove;
- public LoadItem(String path, boolean remove) {
- this.path = path;
- this.remove = remove;
- }
- @Override
- public String toString() {
- return path;
- }
- }
- public static Array<LoadItem> getItems() {
- Array<LoadItem> items = new Array<>();
- for(Field field : ClassReflection.getDeclaredFields(Assetz.class)) {
- if(field.getType() == LoadItem.class) {
- LoadItem item = null;
- try {
- if(!field.isAccessible())
- field.setAccessible(true);
- item = (LoadItem) field.get(null);
- } catch(ReflectionException e) {
- Gdx.app.error("Assetz", "failed to get LoadItem", e);
- }
- if(item != null)
- items.add(item);
- }
- }
- return items;
- }
- public static void removeItems() {
- for(LoadItem item : getItems())
- if(item.remove)
- manager.unload(item.path);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement