Update runtime code

增加资源系统销毁方法。
pull/51/head
hevinci 2022-11-26 16:43:05 +08:00
parent b7e2f084b1
commit abc12d2a1d
2 changed files with 30 additions and 34 deletions

View File

@ -9,6 +9,7 @@ namespace YooAsset
public static partial class YooAssets
{
private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly List<AssetsPackage> _packages = new List<AssetsPackage>();
/// <summary>
@ -23,13 +24,13 @@ namespace YooAsset
{
// 创建驱动器
_isInitialize = true;
UnityEngine.GameObject driverGo = new UnityEngine.GameObject($"[{nameof(YooAssets)}]");
driverGo.AddComponent<YooAssetsDriver>();
UnityEngine.Object.DontDestroyOnLoad(driverGo);
_driver = new UnityEngine.GameObject($"[{nameof(YooAssets)}]");
_driver.AddComponent<YooAssetsDriver>();
UnityEngine.Object.DontDestroyOnLoad(_driver);
#if DEBUG
// 添加远程调试脚本
driverGo.AddComponent<RemoteDebuggerInRuntime>();
_driver.AddComponent<RemoteDebuggerInRuntime>();
#endif
// 初始化异步系统
@ -37,6 +38,31 @@ namespace YooAsset
}
}
/// <summary>
/// 销毁资源系统
/// </summary>
public static void Destroy()
{
if (_isInitialize)
{
OperationSystem.DestroyAll();
DownloadSystem.DestroyAll();
CacheSystem.ClearAll();
foreach (var package in _packages)
{
package.DestroyPackage();
}
_packages.Clear();
if(_driver != null)
GameObject.Destroy(_driver);
_isInitialize = false;
YooLogger.Log("YooAssets destroy all !");
}
}
/// <summary>
/// 更新资源系统
/// </summary>
@ -54,28 +80,6 @@ namespace YooAsset
}
}
/// <summary>
/// 销毁资源系统
/// </summary>
internal static void Destroy()
{
if (_isInitialize)
{
OperationSystem.DestroyAll();
DownloadSystem.DestroyAll();
CacheSystem.ClearAll();
foreach (var package in _packages)
{
package.DestroyPackage();
}
_packages.Clear();
_isInitialize = false;
YooLogger.Log("YooAssets destroy all !");
}
}
/// <summary>
/// 创建资源包

View File

@ -12,14 +12,6 @@ namespace YooAsset
DebugCheckDuplicateDriver();
YooAssets.Update();
}
void OnDestroy()
{
YooAssets.Destroy();
}
void OnApplicationQuit()
{
YooAssets.Destroy();
}
[Conditional("DEBUG")]
private void DebugCheckDuplicateDriver()