111
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 5s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 22s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 35s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 18s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 4s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m5s
Plugin Library CI / publish (08.UniTask) (push) Successful in 4s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 5s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 5s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 22s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 35s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 18s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 4s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m5s
Plugin Library CI / publish (08.UniTask) (push) Successful in 4s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 5s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
This commit is contained in:
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem.meta
Normal file
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd3da5461163cd64ab3441b4a74898b9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d89fa7f5efc28243a1c998e29f158a6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载策略接口,用于抽象不同的资源加载方式(如YooAsset、Resources等)
|
||||
/// </summary>
|
||||
public interface IAssetLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步加载GameObject资源
|
||||
/// </summary>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
/// <param name="packageName">YooAsset包名,Resources模式可忽略</param>
|
||||
/// <returns>加载到的GameObject资源(非实例,是原始Prefab)</returns>
|
||||
Task<GameObject> LoadGameObjectAsync(string assetPath, string packageName = null);
|
||||
|
||||
/// <summary>
|
||||
/// 卸载指定资源,释放底层资源句柄
|
||||
/// </summary>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
void UnloadAsset(string assetPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eee0c2ac899cda04d8ec4a2bb7687195
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
/// <summary>
|
||||
/// 基于Resources的资源加载实现
|
||||
/// </summary>
|
||||
public class ResourcesAssetLoader : IAssetLoader
|
||||
{
|
||||
private readonly Dictionary<string, Object> _assetCache = new Dictionary<string, Object>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过Resources异步加载GameObject资源
|
||||
/// </summary>
|
||||
public async Task<GameObject> LoadGameObjectAsync(string assetPath, string packageName = null)
|
||||
{
|
||||
// Resources模式下忽略packageName
|
||||
var request = Resources.LoadAsync<GameObject>(assetPath);
|
||||
while (!request.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
var asset = request.asset as GameObject;
|
||||
if (asset != null)
|
||||
{
|
||||
_assetCache[assetPath] = asset;
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放Resources加载的资源
|
||||
/// </summary>
|
||||
public void UnloadAsset(string assetPath)
|
||||
{
|
||||
if (_assetCache.TryGetValue(assetPath, out Object asset) && asset != null)
|
||||
{
|
||||
Resources.UnloadAsset(asset);
|
||||
_assetCache.Remove(assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21c72a85d6a282940bb331dfd1c926fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录当前面板的资源路径,用于释放资源句柄
|
||||
/// </summary>
|
||||
private string _assetPath;
|
||||
|
||||
protected BasePanel()
|
||||
{
|
||||
selectableDict = new Dictionary<string, Selectable>();
|
||||
@@ -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<GameObject>(panelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.TryGetPackage(packageName);
|
||||
if (package == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>(panelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = package.LoadAssetAsync<GameObject>(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<Canvas>() && !activePanel.GetComponentInParent<Canvas>())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录当前面板的资源路径,用于释放资源句柄
|
||||
/// </summary>
|
||||
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<GameObject>(panelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.TryGetPackage(packageName);
|
||||
if (package == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>(panelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = package.LoadAssetAsync<GameObject>(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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载器,用于切换不同的资源加载方式(YooAsset、Resources等)
|
||||
/// </summary>
|
||||
IAssetLoader AssetLoader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
@@ -74,6 +79,11 @@ namespace Stary.Evo.UIFarme
|
||||
/// </summary>
|
||||
public class PanelSystem : AbstractSystem, IPanelSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载器
|
||||
/// </summary>
|
||||
public IAssetLoader AssetLoader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 存储普通UI面板
|
||||
/// </summary>
|
||||
@@ -95,8 +105,11 @@ namespace Stary.Evo.UIFarme
|
||||
stackPanel = new Stack<IBasePanel>();
|
||||
queuePanel = new List<IBasePanel>();
|
||||
dicUI = new Dictionary<string, IBasePanel>();
|
||||
if (AssetLoader == null)
|
||||
{
|
||||
Debug.LogError("UnityEvo:AssetLoader is null, please set AssetLoader.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载器,用于切换不同的资源加载方式(YooAsset、Resources等)
|
||||
/// </summary>
|
||||
IAssetLoader AssetLoader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
@@ -81,6 +86,11 @@ namespace Stary.Evo.UIFarme
|
||||
/// </summary>
|
||||
public class SpriteRendererSystem : AbstractSystem, ISpriteRenderSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载器
|
||||
/// </summary>
|
||||
public IAssetLoader AssetLoader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 存储普通UI面板
|
||||
/// </summary>
|
||||
@@ -102,6 +112,10 @@ namespace Stary.Evo.UIFarme
|
||||
stackPanel = new Stack<IBaseRenderPanel>();
|
||||
queuePanel = new List<IBaseRenderPanel>();
|
||||
dicUI = new Dictionary<string, IBaseRenderPanel>();
|
||||
if (AssetLoader == null)
|
||||
{
|
||||
Debug.LogError("UnityEvo:AssetLoader is null, please set AssetLoader.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2,7 +2,8 @@
|
||||
"name": "com.stary.evo.runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UniTask"
|
||||
"UniTask",
|
||||
"DOTween.Modules"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd3da5461163cd64ab3441b4a74898b9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
guid: 5f4a7d7a3938450b943bd8f7bc4d2483
|
||||
timeCreated: 1778823738
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
/// <summary>
|
||||
/// 基于YooAsset的资源加载实现
|
||||
/// </summary>
|
||||
public class YooAssetLoader : IAssetLoader
|
||||
{
|
||||
private readonly Dictionary<string, AssetHandle> _handleCache = new Dictionary<string, AssetHandle>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过YooAsset异步加载GameObject资源
|
||||
/// </summary>
|
||||
public async Task<GameObject> LoadGameObjectAsync(string assetPath, string packageName = null)
|
||||
{
|
||||
AssetHandle handle;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>("Prefabs_"+assetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.TryGetPackage(packageName);
|
||||
if (package == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>("Prefabs_"+assetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = package.LoadAssetAsync<GameObject>("Prefabs_"+assetPath);
|
||||
}
|
||||
}
|
||||
|
||||
await handle.Task;
|
||||
|
||||
// 缓存handle用于后续释放
|
||||
_handleCache[assetPath] = handle;
|
||||
|
||||
return handle.AssetObject as GameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放YooAsset资源句柄
|
||||
/// </summary>
|
||||
public void UnloadAsset(string assetPath)
|
||||
{
|
||||
if (_handleCache.TryGetValue(assetPath, out AssetHandle handle))
|
||||
{
|
||||
handle.Release();
|
||||
_handleCache.Remove(assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 290b84547c578ef48b3b2348f02b9e8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user