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 public static partial class YooAssets
{ {
private static bool _isInitialize = false; private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly List<AssetsPackage> _packages = new List<AssetsPackage>(); private static readonly List<AssetsPackage> _packages = new List<AssetsPackage>();
/// <summary> /// <summary>
@ -23,13 +24,13 @@ namespace YooAsset
{ {
// 创建驱动器 // 创建驱动器
_isInitialize = true; _isInitialize = true;
UnityEngine.GameObject driverGo = new UnityEngine.GameObject($"[{nameof(YooAssets)}]"); _driver = new UnityEngine.GameObject($"[{nameof(YooAssets)}]");
driverGo.AddComponent<YooAssetsDriver>(); _driver.AddComponent<YooAssetsDriver>();
UnityEngine.Object.DontDestroyOnLoad(driverGo); UnityEngine.Object.DontDestroyOnLoad(_driver);
#if DEBUG #if DEBUG
// 添加远程调试脚本 // 添加远程调试脚本
driverGo.AddComponent<RemoteDebuggerInRuntime>(); _driver.AddComponent<RemoteDebuggerInRuntime>();
#endif #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>
/// 更新资源系统 /// 更新资源系统
/// </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> /// <summary>
/// 创建资源包 /// 创建资源包

View File

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