using UnityEngine;
using CreatGame.AssetBundle;
using System.Collections.Generic;
using UnityEngine.U2D;
namespace CreatGame.UI
{
///
/// ui上的资源加载器
///
public class UILoader
{
private List m_GameObjectCache = new List();
private List m_SpriteCache = new List();
///
/// 同步资源加载
///
///
///
public GameObject LoadGameObject(string name)
{
var gameObj = AssetBundleManager.Instance.LoadGameObject(name);
if (gameObj == null)
{
return null;
}
m_GameObjectCache.Add(gameObj);
return gameObj;
}
///
/// 异步加载预制件
///
///
///
public void LoadGameObjectAsync(string name, System.Action callback)
{
AssetBundleManager.Instance.LoadGameObjectAsync(name, (obj) =>
{
if (obj != null)
{
m_GameObjectCache.Add(obj);
}
callback(obj);
});
}
///
///
///
///
///
///
public Sprite LoadSprite(string atlasName, string spriteName)
{
var spriteAtlas = AssetBundleManager.Instance.LoadSpriteAtlas(atlasName);
if (spriteAtlas == null)
{
return null;
}
return spriteAtlas.GetSprite(spriteName);
}
public void DisposeGameObjectCache()
{
var count = m_GameObjectCache.Count;
for (int i = 0; i < count; i++)
{
var obj = m_GameObjectCache[0];
m_GameObjectCache.RemoveAt(0);
GameObject.Destroy(obj);
}
}
}
}