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; }
/// <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()
{
if (_isInitialize)
throw new Exception("YooAssets is initialized !");
throw new Exception($"{nameof(YooAssets)} is initialized !");
// 创建驱动器
if (_isInitialize == false)
{
// 创建驱动器
_isInitialize = true;
UnityEngine.GameObject driverGo = new UnityEngine.GameObject("[YooAsset]");
UnityEngine.GameObject driverGo = new UnityEngine.GameObject($"[{nameof(YooAssets)}]");
driverGo.AddComponent<YooAssetDriver>();
UnityEngine.Object.DontDestroyOnLoad(driverGo);
#if DEBUG
// 添加远程调试脚本
driverGo.AddComponent<RemoteDebuggerInRuntime>();
#endif
@ -83,7 +84,7 @@ namespace YooAsset
public static YooAssetPackage CreateAssetPackage(string packageName)
{
if (_isInitialize == false)
throw new Exception("YooAssets not initialize !");
throw new Exception($"{nameof(YooAssets)} not initialize !");
if (string.IsNullOrEmpty(packageName))
throw new Exception("PackageName is null or empty !");
@ -96,12 +97,37 @@ namespace YooAsset
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>
/// <param name="packageName">资源包名称</param>
public static bool HasAssetPackage(string packageName)
{
if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !");
foreach (var package in _packages)
{
if (package.PackageName == packageName)

View File

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