refactor : 重构代码
This commit is contained in:
@@ -10,12 +10,12 @@ namespace YooAsset
|
||||
internal class ResourceManager
|
||||
{
|
||||
internal readonly Dictionary<string, ProviderOperation> ProviderDic = new Dictionary<string, ProviderOperation>(5000);
|
||||
internal readonly Dictionary<string, LoadBundleFileOperation> LoaderDic = new Dictionary<string, LoadBundleFileOperation>(5000);
|
||||
internal readonly Dictionary<string, LoadBundleOperation> LoaderDic = new Dictionary<string, LoadBundleOperation>(5000);
|
||||
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
|
||||
private FileSystemHost _fileSystemHost;
|
||||
private long _sceneCreateIndex = 0;
|
||||
private IBundleQuery _bundleQuery;
|
||||
private int _bundleLoadingMaxConcurrency;
|
||||
|
||||
|
||||
// 开发者配置选项
|
||||
public bool AutoUnloadBundleWhenUnused { private set; get; }
|
||||
public bool WebGLForceSyncLoadAsset { private set; get; }
|
||||
@@ -44,12 +44,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public void Initialize(InitializePackageOptions options, IBundleQuery bundleServices)
|
||||
public void Initialize(InitializePackageOptions options, FileSystemHost host)
|
||||
{
|
||||
_fileSystemHost = host;
|
||||
_bundleLoadingMaxConcurrency = options.BundleLoadingMaxConcurrency;
|
||||
AutoUnloadBundleWhenUnused = options.AutoUnloadBundleWhenUnused;
|
||||
WebGLForceSyncLoadAsset = options.WebGLForceSyncLoadAsset;
|
||||
_bundleQuery = bundleServices;
|
||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace YooAsset
|
||||
loopCount--;
|
||||
|
||||
// 卸载主资源包加载器
|
||||
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo.Asset.BundleID);
|
||||
string mainBundleName = _fileSystemHost.GetMainBundleName(assetInfo.Asset.BundleID);
|
||||
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
||||
if (mainLoader != null)
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace YooAsset
|
||||
// 卸载依赖资源包加载器
|
||||
foreach (var dependID in assetInfo.Asset.DependBundleIDs)
|
||||
{
|
||||
string dependBundleName = _bundleQuery.GetMainBundleName(dependID);
|
||||
string dependBundleName = _fileSystemHost.GetMainBundleName(dependID);
|
||||
var dependLoader = TryGetBundleFileLoader(dependBundleName);
|
||||
if (dependLoader != null)
|
||||
{
|
||||
@@ -296,15 +296,15 @@ namespace YooAsset
|
||||
return provider.CreateHandle<RawFileHandle>();
|
||||
}
|
||||
|
||||
internal LoadBundleFileOperation CreateMainBundleFileLoader(AssetInfo assetInfo)
|
||||
internal LoadBundleOperation CreateMainBundleFileLoader(AssetInfo assetInfo)
|
||||
{
|
||||
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
|
||||
BundleInfo bundleInfo = _fileSystemHost.GetMainBundleInfo(assetInfo);
|
||||
return CreateBundleFileLoaderInternal(bundleInfo);
|
||||
}
|
||||
internal List<LoadBundleFileOperation> CreateDependBundleFileLoaders(AssetInfo assetInfo)
|
||||
internal List<LoadBundleOperation> CreateDependBundleFileLoaders(AssetInfo assetInfo)
|
||||
{
|
||||
List<BundleInfo> bundleInfos = _bundleQuery.GetDependBundleInfos(assetInfo);
|
||||
List<LoadBundleFileOperation> result = new List<LoadBundleFileOperation>(bundleInfos.Count);
|
||||
List<BundleInfo> bundleInfos = _fileSystemHost.GetDependBundleInfos(assetInfo);
|
||||
List<LoadBundleOperation> result = new List<LoadBundleOperation>(bundleInfos.Count);
|
||||
foreach (var bundleInfo in bundleInfos)
|
||||
{
|
||||
var bundleLoader = CreateBundleFileLoaderInternal(bundleInfo);
|
||||
@@ -321,7 +321,7 @@ namespace YooAsset
|
||||
}
|
||||
internal bool CheckBundleDestroyed(int bundleID)
|
||||
{
|
||||
string bundleName = _bundleQuery.GetMainBundleName(bundleID);
|
||||
string bundleName = _fileSystemHost.GetMainBundleName(bundleID);
|
||||
var bundleFileLoader = TryGetBundleFileLoader(bundleName);
|
||||
if (bundleFileLoader == null)
|
||||
return true;
|
||||
@@ -329,7 +329,7 @@ namespace YooAsset
|
||||
}
|
||||
internal bool CheckBundleReleasable(int bundleID)
|
||||
{
|
||||
string bundleName = _bundleQuery.GetMainBundleName(bundleID);
|
||||
string bundleName = _fileSystemHost.GetMainBundleName(bundleID);
|
||||
var bundleFileLoader = TryGetBundleFileLoader(bundleName);
|
||||
if (bundleFileLoader == null)
|
||||
return true;
|
||||
@@ -344,22 +344,22 @@ namespace YooAsset
|
||||
return BundleLoadingCounter >= _bundleLoadingMaxConcurrency;
|
||||
}
|
||||
|
||||
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
|
||||
private LoadBundleOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
|
||||
{
|
||||
// 如果加载器已经存在
|
||||
string bundleName = bundleInfo.Bundle.BundleName;
|
||||
LoadBundleFileOperation loaderOperation = TryGetBundleFileLoader(bundleName);
|
||||
LoadBundleOperation loaderOperation = TryGetBundleFileLoader(bundleName);
|
||||
if (loaderOperation != null)
|
||||
return loaderOperation;
|
||||
|
||||
// 新增下载需求
|
||||
loaderOperation = new LoadBundleFileOperation(this, bundleInfo);
|
||||
loaderOperation = new LoadBundleOperation(this, bundleInfo);
|
||||
LoaderDic.Add(bundleName, loaderOperation);
|
||||
return loaderOperation;
|
||||
}
|
||||
private LoadBundleFileOperation TryGetBundleFileLoader(string bundleName)
|
||||
private LoadBundleOperation TryGetBundleFileLoader(string bundleName)
|
||||
{
|
||||
if (LoaderDic.TryGetValue(bundleName, out LoadBundleFileOperation value))
|
||||
if (LoaderDic.TryGetValue(bundleName, out LoadBundleOperation value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user