Update runtime code

移除了YooAssets.IsInitialized字段
增加了YooAssets.InitializeStatus字段
pull/51/head
hevinci 2022-10-12 15:01:39 +08:00
parent 1de9e0b79d
commit c2192dd657
3 changed files with 39 additions and 12 deletions

View File

@ -25,11 +25,11 @@ namespace YooAsset
public string PackageName { private set; get; } public string PackageName { private set; get; }
/// <summary> /// <summary>
/// 是否已经初始化 /// 初始化状态
/// </summary> /// </summary>
public bool IsInitialized public EOperationStatus InitializeStatus
{ {
get { return _isInitialize; } get { return _initializeStatus; }
} }

View File

@ -17,17 +17,18 @@ namespace YooAsset
public static void Initialize() public static void Initialize()
{ {
if (_isInitialize) if (_isInitialize)
throw new Exception("YooAssets is initialized !"); throw new Exception($"{nameof(YooAssets)} is initialized !");
// 创建驱动器
if (_isInitialize == false) if (_isInitialize == false)
{ {
// 创建驱动器
_isInitialize = true; _isInitialize = true;
UnityEngine.GameObject driverGo = new UnityEngine.GameObject("[YooAsset]"); UnityEngine.GameObject driverGo = new UnityEngine.GameObject($"[{nameof(YooAssets)}]");
driverGo.AddComponent<YooAssetDriver>(); driverGo.AddComponent<YooAssetDriver>();
UnityEngine.Object.DontDestroyOnLoad(driverGo); UnityEngine.Object.DontDestroyOnLoad(driverGo);
#if DEBUG #if DEBUG
// 添加远程调试脚本
driverGo.AddComponent<RemoteDebuggerInRuntime>(); driverGo.AddComponent<RemoteDebuggerInRuntime>();
#endif #endif
@ -83,7 +84,7 @@ namespace YooAsset
public static YooAssetPackage CreateAssetPackage(string packageName) public static YooAssetPackage CreateAssetPackage(string packageName)
{ {
if (_isInitialize == false) if (_isInitialize == false)
throw new Exception("YooAssets not initialize !"); throw new Exception($"{nameof(YooAssets)} not initialize !");
if (string.IsNullOrEmpty(packageName)) if (string.IsNullOrEmpty(packageName))
throw new Exception("PackageName is null or empty !"); throw new Exception("PackageName is null or empty !");
@ -96,12 +97,37 @@ namespace YooAsset
return component; return component;
} }
/// <summary>
/// 获取资源包
/// </summary>
/// <param name="packageName">资源包名称</param>
public static YooAssetPackage GetAssetPackage(string packageName)
{
if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !");
if (string.IsNullOrEmpty(packageName))
throw new Exception("Package name is null or empty !");
foreach (var package in _packages)
{
if (package.PackageName == packageName)
return package;
}
YooLogger.Warning($"Not found asset package : {packageName}");
return null;
}
/// <summary> /// <summary>
/// 检测资源包是否存在 /// 检测资源包是否存在
/// </summary> /// </summary>
/// <param name="packageName">资源包名称</param> /// <param name="packageName">资源包名称</param>
public static bool HasAssetPackage(string packageName) public static bool HasAssetPackage(string packageName)
{ {
if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !");
foreach (var package in _packages) foreach (var package in _packages)
{ {
if (package.PackageName == packageName) if (package.PackageName == packageName)

View File

@ -11,18 +11,19 @@ namespace YooAsset
private static YooAssetPackage _mainPackage; private static YooAssetPackage _mainPackage;
/// <summary> /// <summary>
/// 是否已经初始化 /// 初始化状态
/// </summary> /// </summary>
public static bool IsInitialized public static EOperationStatus InitializeStatus
{ {
get get
{ {
if (_mainPackage == null) if (_mainPackage == null)
return false; return EOperationStatus.None;
return _mainPackage.IsInitialized; return _mainPackage.InitializeStatus;
} }
} }
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>