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;
}
}
}