diff --git a/Assets/00.StaryEvo/Runtime/Tool/PanelSystem.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem.meta new file mode 100644 index 0000000..1f1ea2a --- /dev/null +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bd3da5461163cd64ab3441b4a74898b9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader.meta new file mode 100644 index 0000000..fe25493 --- /dev/null +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4d89fa7f5efc28243a1c998e29f158a6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/IAssetLoader.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/IAssetLoader.cs new file mode 100644 index 0000000..3747fbf --- /dev/null +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/IAssetLoader.cs @@ -0,0 +1,25 @@ +using System.Threading.Tasks; +using UnityEngine; + +namespace Stary.Evo.UIFarme +{ + /// + /// 资源加载策略接口,用于抽象不同的资源加载方式(如YooAsset、Resources等) + /// + public interface IAssetLoader + { + /// + /// 异步加载GameObject资源 + /// + /// 资源路径 + /// YooAsset包名,Resources模式可忽略 + /// 加载到的GameObject资源(非实例,是原始Prefab) + Task LoadGameObjectAsync(string assetPath, string packageName = null); + + /// + /// 卸载指定资源,释放底层资源句柄 + /// + /// 资源路径 + void UnloadAsset(string assetPath); + } +} diff --git a/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/IAssetLoader.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/IAssetLoader.cs.meta new file mode 100644 index 0000000..62a9fe6 --- /dev/null +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/IAssetLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eee0c2ac899cda04d8ec4a2bb7687195 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/ResourcesAssetLoader.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/ResourcesAssetLoader.cs new file mode 100644 index 0000000..40dd3ad --- /dev/null +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/ResourcesAssetLoader.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +namespace Stary.Evo.UIFarme +{ + /// + /// 基于Resources的资源加载实现 + /// + public class ResourcesAssetLoader : IAssetLoader + { + private readonly Dictionary _assetCache = new Dictionary(); + + /// + /// 通过Resources异步加载GameObject资源 + /// + public async Task LoadGameObjectAsync(string assetPath, string packageName = null) + { + // Resources模式下忽略packageName + var request = Resources.LoadAsync(assetPath); + while (!request.isDone) + { + await Task.Yield(); + } + + var asset = request.asset as GameObject; + if (asset != null) + { + _assetCache[assetPath] = asset; + } + + return asset; + } + + /// + /// 释放Resources加载的资源 + /// + public void UnloadAsset(string assetPath) + { + if (_assetCache.TryGetValue(assetPath, out Object asset) && asset != null) + { + Resources.UnloadAsset(asset); + _assetCache.Remove(assetPath); + } + } + } +} diff --git a/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/ResourcesAssetLoader.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/ResourcesAssetLoader.cs.meta new file mode 100644 index 0000000..76225b8 --- /dev/null +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/AssetLoader/ResourcesAssetLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 21c72a85d6a282940bb331dfd1c926fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BasePanel.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs similarity index 91% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BasePanel.cs rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs index 6724691..7d098ab 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BasePanel.cs +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs @@ -1,10 +1,9 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using DG.Tweening; using UnityEngine; using UnityEngine.UI; -using YooAsset; namespace Stary.Evo.UIFarme { @@ -104,6 +103,11 @@ namespace Stary.Evo.UIFarme protected GameObject activePanel { get; private set; } + /// + /// 记录当前面板的资源路径,用于释放资源句柄 + /// + private string _assetPath; + protected BasePanel() { selectableDict = new Dictionary(); @@ -199,32 +203,18 @@ namespace Stary.Evo.UIFarme { return activePanel.gameObject; } - AssetHandle handle = null; - if (packageName == null) + + _assetPath = panelName; + var asset = await PanelSystem.AssetLoader.LoadGameObjectAsync(panelName, packageName); + if (asset == null) { - handle = YooAssets.LoadAssetAsync(panelName); - } - else - { - var package = YooAssets.TryGetPackage(packageName); - if (package == null) - { - handle = YooAssets.LoadAssetAsync(panelName); - } - else - { - handle = package.LoadAssetAsync(panelName); - } + Debug.LogError($"UnityEvo:资源加载失败,{panelName}未找到!"); + return null; } - await handle.Task; - - activePanel = GameObject.Instantiate(handle.AssetObject as GameObject, panelParent); - - + activePanel = GameObject.Instantiate(asset, panelParent); activePanel.name = this.GetType().Name; - if (!activePanel.GetComponentInChildren() && !activePanel.GetComponentInParent()) { Debug.LogError($"UnityEvo:panelParent上不存在Canvas组件,{panelName}无法正常运行,进程已中断,请检查!!!!!"); @@ -239,6 +229,11 @@ namespace Stary.Evo.UIFarme if (activePanel != null) { GameObject.Destroy(activePanel); + if (!string.IsNullOrEmpty(_assetPath)) + { + PanelSystem.AssetLoader.UnloadAsset(_assetPath); + _assetPath = null; + } PanelSystem.Get_Dic().Remove(this.GetType().Name); } } diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BasePanel.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BasePanel.cs.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BaseRenderPanel.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BaseRenderPanel.cs similarity index 90% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BaseRenderPanel.cs rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BaseRenderPanel.cs index 06f17fd..c09ed46 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BaseRenderPanel.cs +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BaseRenderPanel.cs @@ -1,10 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using DG.Tweening; using UnityEngine; -using UnityEngine.UI; -using YooAsset; namespace Stary.Evo.UIFarme { @@ -100,6 +98,11 @@ namespace Stary.Evo.UIFarme protected GameObject activePanel { get; private set; } + /// + /// 记录当前面板的资源路径,用于释放资源句柄 + /// + private string _assetPath; + public virtual void Initialize(GameObject panelGo) { @@ -161,28 +164,16 @@ namespace Stary.Evo.UIFarme { return activePanel.gameObject; } - AssetHandle handle = null; - if (packageName == null) + + _assetPath = panelName; + var asset = await PanelSystem.AssetLoader.LoadGameObjectAsync(panelName, packageName); + if (asset == null) { - handle = YooAssets.LoadAssetAsync(panelName); - } - else - { - var package = YooAssets.TryGetPackage(packageName); - if (package == null) - { - handle = YooAssets.LoadAssetAsync(panelName); - } - else - { - handle = package.LoadAssetAsync(panelName); - } + Debug.LogError($"UnityEvo:资源加载失败,{panelName}未找到!"); + return null; } - await handle.Task; - - activePanel = GameObject.Instantiate(handle.AssetObject as GameObject, panelParent); - + activePanel = GameObject.Instantiate(asset, panelParent); activePanel.name = panelName; return activePanel; @@ -193,6 +184,11 @@ namespace Stary.Evo.UIFarme if (activePanel != null) { GameObject.Destroy(activePanel); + if (!string.IsNullOrEmpty(_assetPath)) + { + PanelSystem.AssetLoader.UnloadAsset(_assetPath); + _assetPath = null; + } PanelSystem.Get_Dic().Remove(this.GetType().Name); } } diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BaseRenderPanel.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BaseRenderPanel.cs.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Base/BaseRenderPanel.cs.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BaseRenderPanel.cs.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/PanelSystem.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/PanelSystem.cs similarity index 94% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/PanelSystem.cs rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/PanelSystem.cs index 3146a6e..37b8c73 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/PanelSystem.cs +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/PanelSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; @@ -7,6 +7,11 @@ namespace Stary.Evo.UIFarme { public interface IPanelSystem : ISystem { + /// + /// 资源加载器,用于切换不同的资源加载方式(YooAsset、Resources等) + /// + IAssetLoader AssetLoader { get; set; } + /// /// UI的入栈操作,此操作会显示一个面板 /// @@ -74,6 +79,11 @@ namespace Stary.Evo.UIFarme /// public class PanelSystem : AbstractSystem, IPanelSystem { + /// + /// 资源加载器 + /// + public IAssetLoader AssetLoader { get; set; } + /// /// 存储普通UI面板 /// @@ -95,8 +105,11 @@ namespace Stary.Evo.UIFarme stackPanel = new Stack(); queuePanel = new List(); dicUI = new Dictionary(); + if (AssetLoader == null) + { + Debug.LogError("UnityEvo:AssetLoader is null, please set AssetLoader."); + } } - /// /// UI的入栈操作,此操作会显示一个面板 /// @@ -118,7 +131,7 @@ namespace Stary.Evo.UIFarme nextPanel.UIName = panelName; await nextPanel.InitializeAsync(this); nextPanel.SetPanelParent(parent); - GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{prefabName}", packageName); + GameObject panelGo = await nextPanel.CreatePanel(prefabName, packageName); ///生成面板后,进行初始化操作 await nextPanel.InitializeAsync(panelGo); dicUI.Add(panelName, nextPanel); @@ -162,7 +175,7 @@ namespace Stary.Evo.UIFarme nextPanel.UIName = panelName; await nextPanel.InitializeAsync(this); nextPanel.SetPanelParent(parent); - GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{prefabName}", packageName); + GameObject panelGo = await nextPanel.CreatePanel(prefabName, packageName); ///生成面板后,进行初始化操作 await nextPanel.InitializeAsync(panelGo); diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/PanelSystem.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/PanelSystem.cs.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/PanelSystem.cs.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/PanelSystem.cs.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/SpriteRendererSystem.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/SpriteRendererSystem.cs similarity index 96% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/SpriteRendererSystem.cs rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/SpriteRendererSystem.cs index c2bd056..ca35cd4 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/SpriteRendererSystem.cs +++ b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/SpriteRendererSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; @@ -7,6 +7,11 @@ namespace Stary.Evo.UIFarme { public interface ISpriteRenderSystem : ISystem { + /// + /// 资源加载器,用于切换不同的资源加载方式(YooAsset、Resources等) + /// + IAssetLoader AssetLoader { get; set; } + /// /// UI的入栈操作,此操作会显示一个面板 /// @@ -81,6 +86,11 @@ namespace Stary.Evo.UIFarme /// public class SpriteRendererSystem : AbstractSystem, ISpriteRenderSystem { + /// + /// 资源加载器 + /// + public IAssetLoader AssetLoader { get; set; } + /// /// 存储普通UI面板 /// @@ -102,6 +112,10 @@ namespace Stary.Evo.UIFarme stackPanel = new Stack(); queuePanel = new List(); dicUI = new Dictionary(); + if (AssetLoader == null) + { + Debug.LogError("UnityEvo:AssetLoader is null, please set AssetLoader."); + } } /// diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/SpriteRendererSystem.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/SpriteRendererSystem.cs.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/Manager/SpriteRendererSystem.cs.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/SpriteRendererSystem.cs.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/UITool.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/UITool.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool.meta diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/UITool/UITool.cs b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool/UITool.cs similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/UITool/UITool.cs rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool/UITool.cs diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/UITool/UITool.cs.meta b/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool/UITool.cs.meta similarity index 100% rename from Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/UITool/UITool.cs.meta rename to Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool/UITool.cs.meta diff --git a/Assets/00.StaryEvo/Runtime/com.stary.evo.runtime.asmdef b/Assets/00.StaryEvo/Runtime/com.stary.evo.runtime.asmdef index 7a91ead..576a3e6 100644 --- a/Assets/00.StaryEvo/Runtime/com.stary.evo.runtime.asmdef +++ b/Assets/00.StaryEvo/Runtime/com.stary.evo.runtime.asmdef @@ -2,7 +2,8 @@ "name": "com.stary.evo.runtime", "rootNamespace": "", "references": [ - "UniTask" + "UniTask", + "DOTween.Modules" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/00.StaryEvo/package.json b/Assets/00.StaryEvo/package.json index cc63eb3..e4def5d 100644 --- a/Assets/00.StaryEvo/package.json +++ b/Assets/00.StaryEvo/package.json @@ -1,6 +1,6 @@ { "name": "com.staryevo.main", - "version": "2.1.15", + "version": "2.1.16", "displayName": "00.StaryEvo", "description": "This is an Framework package(后台服务器版本,端口9527)", "unity": "2021.3", diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem.meta b/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem.meta index 1f1ea2a..b2a23db 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem.meta +++ b/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem.meta @@ -1,8 +1,3 @@ fileFormatVersion: 2 -guid: bd3da5461163cd64ab3441b4a74898b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: +guid: 5f4a7d7a3938450b943bd8f7bc4d2483 +timeCreated: 1778823738 \ No newline at end of file diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/YooAssetLoader.cs b/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/YooAssetLoader.cs new file mode 100644 index 0000000..5b82e62 --- /dev/null +++ b/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/YooAssetLoader.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using YooAsset; + +namespace Stary.Evo.UIFarme +{ + /// + /// 基于YooAsset的资源加载实现 + /// + public class YooAssetLoader : IAssetLoader + { + private readonly Dictionary _handleCache = new Dictionary(); + + /// + /// 通过YooAsset异步加载GameObject资源 + /// + public async Task LoadGameObjectAsync(string assetPath, string packageName = null) + { + AssetHandle handle; + if (string.IsNullOrEmpty(packageName)) + { + handle = YooAssets.LoadAssetAsync("Prefabs_"+assetPath); + } + else + { + var package = YooAssets.TryGetPackage(packageName); + if (package == null) + { + handle = YooAssets.LoadAssetAsync("Prefabs_"+assetPath); + } + else + { + handle = package.LoadAssetAsync("Prefabs_"+assetPath); + } + } + + await handle.Task; + + // 缓存handle用于后续释放 + _handleCache[assetPath] = handle; + + return handle.AssetObject as GameObject; + } + + /// + /// 释放YooAsset资源句柄 + /// + public void UnloadAsset(string assetPath) + { + if (_handleCache.TryGetValue(assetPath, out AssetHandle handle)) + { + handle.Release(); + _handleCache.Remove(assetPath); + } + } + } +} diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/YooAssetLoader.cs.meta b/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/YooAssetLoader.cs.meta new file mode 100644 index 0000000..a744825 --- /dev/null +++ b/Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem/YooAssetLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 290b84547c578ef48b3b2348f02b9e8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/00.StaryEvoTools/package.json b/Assets/00.StaryEvoTools/package.json index 7a3772c..17f74c1 100644 --- a/Assets/00.StaryEvoTools/package.json +++ b/Assets/00.StaryEvoTools/package.json @@ -1,6 +1,6 @@ { "name": "com.staryevo.tools", - "version": "1.4.28", + "version": "1.5.0", "displayName": "00.StaryEvo.Tools", "description": "This is an Framework package(后台服务器版本,端口9527)", "unity": "2021.3",