60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace BF
|
|
{
|
|
public enum EAssetLoadStatus
|
|
{
|
|
Wait, //等待加载
|
|
Loading, //加载中
|
|
Complete, //加载完成
|
|
Error, //加载完成,但出现错误
|
|
Unloading, //卸载过程中
|
|
Unloaded, //卸载完成
|
|
}
|
|
|
|
public abstract class AssetObjectBase
|
|
{
|
|
private static uint IdIndex = 0;
|
|
|
|
public uint Id { get; protected set; }
|
|
|
|
public string AssetPath { get; protected set; }
|
|
|
|
public System.Type AssetType { get; protected set; }
|
|
|
|
public uint RefCount { get; protected set; }
|
|
|
|
public EAssetLoadStatus LoadStatus { get; set; }
|
|
|
|
public Object Asset { get; protected set; }
|
|
|
|
protected float unloadCountdownTime;
|
|
|
|
public AssetObjectBase(string assetPath, System.Type type)
|
|
{
|
|
Id = ++IdIndex;
|
|
AssetType = type;
|
|
AssetPath = assetPath;
|
|
LoadStatus = EAssetLoadStatus.Wait;
|
|
}
|
|
|
|
public virtual bool Tick() { return true; }
|
|
|
|
public abstract bool Unload(bool immediately);
|
|
|
|
public void UnloadCountdown(bool immediately)
|
|
{
|
|
if (immediately || unloadCountdownTime <= Time.time)
|
|
{
|
|
if (OnUnloadComplete())
|
|
{
|
|
LoadStatus = EAssetLoadStatus.Unloaded;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected abstract bool OnUnloadComplete();
|
|
|
|
}
|
|
}
|