From c2192dd6576df6624ebf3b8d0b66928dc38f0a3f Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 12 Oct 2022 15:01:39 +0800 Subject: [PATCH] Update runtime code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了YooAssets.IsInitialized字段 增加了YooAssets.InitializeStatus字段 --- Assets/YooAsset/Runtime/YooAssetPackage.cs | 6 ++-- Assets/YooAsset/Runtime/YooAssets.cs | 34 ++++++++++++++++--- Assets/YooAsset/Runtime/YooAssetsExtension.cs | 11 +++--- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Assets/YooAsset/Runtime/YooAssetPackage.cs b/Assets/YooAsset/Runtime/YooAssetPackage.cs index 4db450f..1029666 100644 --- a/Assets/YooAsset/Runtime/YooAssetPackage.cs +++ b/Assets/YooAsset/Runtime/YooAssetPackage.cs @@ -25,11 +25,11 @@ namespace YooAsset public string PackageName { private set; get; } /// - /// 是否已经初始化 + /// 初始化状态 /// - public bool IsInitialized + public EOperationStatus InitializeStatus { - get { return _isInitialize; } + get { return _initializeStatus; } } diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index a55404f..4f92cb6 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -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(); UnityEngine.Object.DontDestroyOnLoad(driverGo); #if DEBUG + // 添加远程调试脚本 driverGo.AddComponent(); #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; } + /// + /// 获取资源包 + /// + /// 资源包名称 + 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; + } + /// /// 检测资源包是否存在 /// /// 资源包名称 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) diff --git a/Assets/YooAsset/Runtime/YooAssetsExtension.cs b/Assets/YooAsset/Runtime/YooAssetsExtension.cs index 4abf39f..b10d291 100644 --- a/Assets/YooAsset/Runtime/YooAssetsExtension.cs +++ b/Assets/YooAsset/Runtime/YooAssetsExtension.cs @@ -11,18 +11,19 @@ namespace YooAsset private static YooAssetPackage _mainPackage; /// - /// 是否已经初始化 + /// 初始化状态 /// - public static bool IsInitialized + public static EOperationStatus InitializeStatus { - get + get { if (_mainPackage == null) - return false; - return _mainPackage.IsInitialized; + return EOperationStatus.None; + return _mainPackage.InitializeStatus; } } + /// /// 异步初始化 ///