using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingleABLoader : System.IDisposable
{
private AssetLoader _AssetLoader;
private string _ABName;
private string _ABLoadPath;
public SingleABLoader(string abName)
{
_ABName = abName;
_ABLoadPath = PathTools.GetABPath() + "/" + _ABName;//
Debug.Log("_ABLoadPath=" + _ABLoadPath);
}
/// <summary>
/// 加载AB包
/// </summary>
public void LoadAssetBundle()
{
_AssetLoader = new AssetLoader(AssetBundle.LoadFromFile(_ABLoadPath));
}
/// <summary>
/// 加载ab包中指定的资源
/// </summary>
/// <param name="asstName"></param>
/// <param name="isCache"></param>
/// <returns></returns>
public UnityEngine.Object LoadAsset(string assetName, bool isCache = false)
{
if (_AssetLoader != null)
{
return _AssetLoader.LoadAsset(assetName, isCache);
}
Debug.LogError(GetType() + "/LoadAsset()/参数_AssetLoader = null!,请检查");
return null;
}
/// <summary>
/// 卸载指定资源
/// /// </summary>
/// <param name="asset">资源名称</param>
/// <returns></returns>
public void UnLoadAsset(UnityEngine.Object asset)
{
_AssetLoader.UnLoadAsset(asset);
}
/// <summary>
/// //释放资源
/// </summary>
void IDisposable.Dispose()
{
if (_AssetLoader != null)
{
_AssetLoader.Dispose();
_AssetLoader = null;
}
else
{
Debug.LogError(GetType() + "/UnLoadAsset()/参数 _AssetLoader== null 请检查");
}
}
/// <summary>
/// //释放当前AssetBundle资源包 ,且卸载所有资源
/// </summary>
public void DisposeAll()
{
if (_AssetLoader != null)
{
_AssetLoader.DisposeAll();
_AssetLoader = null;
}
else
{
Debug.LogError(GetType() + "/UnLoadAsset()/参数 _AssetLoader== null 请检查");
}
}
/// <summary>
/// 查询当前AssetBundle中包含的所有资源名称
/// </summary>
/// <returns></returns>
public string[] RetriveAllAssetName()
{
if (_AssetLoader != null)
{
return _AssetLoader.RetriveAllAssetName();
}
else
{
Debug.LogError(GetType() + "/UnLoadAsset()/参数 _AssetLoader== null 请检查");
return null;
}
}
}