From ece5fc6192739ec18692cc9ef0000b09ba1bf154 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 04 六月 2025 15:08:57 +0800
Subject: [PATCH] 18 子 2D卡牌客户端搭建 / 2D卡牌客户端搭建 备注: 1.资源加载统一入口 2.创建组件层级改为UI
---
Main/Core/SFX/SFXPlayUtility.cs | 8
Main/Component/UI/Effect/EffectMgr.cs | 20 +
Main/Utility/MaterialUtility.cs | 72 ----
Main/System/Login/LoginWin.cs | 8
Main/System/Message/ImgAnalysis.cs | 3
Main/System/KnapSack/Logic/CommonGetItemWin.cs | 14
Main/UI/UIBase.cs | 21
Main/ResModule/UILoader.cs | 402 +++-----------------------
Main/UI/LoadingWin.cs | 8
/dev/null | 12
Main/UI/UIManager.cs | 213 ++++++++++---
Main/Manager/ResManager.cs | 110 ++++--
Main/Core/ResModule/GameObjectPoolManager.cs | 3
13 files changed, 327 insertions(+), 567 deletions(-)
diff --git a/Main/Component/UI/Effect/EffectMgr.cs b/Main/Component/UI/Effect/EffectMgr.cs
index fe7ed5a..fee045b 100644
--- a/Main/Component/UI/Effect/EffectMgr.cs
+++ b/Main/Component/UI/Effect/EffectMgr.cs
@@ -6,7 +6,14 @@
{
public UIEffectBehaviour GetUIEffect(int id, bool _destroy = false)
{
- var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect", id.ToString());
+ EffectConfig effectCfg = EffectConfig.Get(id);
+
+ if (null == effectCfg)
+ {
+ return null;
+ }
+
+ var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectCfg.packageName, effectCfg.fxName);
if (_prefab == null)
{
return null;
@@ -106,12 +113,19 @@
public void RecyleUIEffect(int id, GameObject _effectObj)
{
- var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect", id.ToString());
- _effectObj.SetActive(false);
+ EffectConfig effectCfg = EffectConfig.Get(id);
+
+ if (null == effectCfg)
+ {
+ return;
+ }
+
+ var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectCfg.packageName, effectCfg.fxName);
if (_prefab == null)
{
return;
}
+
GameObjectPoolManager.GameObjectPool _pool = GameObjectPoolManager.Instance.RequestPool(_prefab);
if (_pool != null)
{
diff --git a/Main/Core/ResModule/GameObjectPoolManager.cs b/Main/Core/ResModule/GameObjectPoolManager.cs
index dd958a2..eb3a521 100644
--- a/Main/Core/ResModule/GameObjectPoolManager.cs
+++ b/Main/Core/ResModule/GameObjectPoolManager.cs
@@ -371,7 +371,8 @@
if (!string.IsNullOrEmpty(assetBundleName) && !string.IsNullOrEmpty(assetName))
{
- ResManager.Instance.UnloadAsset(assetBundleName);
+ ResManager.Instance.UnloadAsset(assetBundleName, assetName);
+ ResManager.Instance.UnloadAssetBundle(assetBundleName, true, false);
}
}
diff --git a/Main/Core/SFX/SFXPlayUtility.cs b/Main/Core/SFX/SFXPlayUtility.cs
index ec9b583..eeae435 100644
--- a/Main/Core/SFX/SFXPlayUtility.cs
+++ b/Main/Core/SFX/SFXPlayUtility.cs
@@ -237,8 +237,14 @@
private SFXController Create(int id)
{
- GameObject _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect", id.ToString());
+ EffectConfig effectCfg = EffectConfig.Get(id);
+ if (null == effectCfg)
+ {
+ return null;
+ }
+
+ var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectCfg.packageName, effectCfg.fxName);
if (_prefab == null)
{
return null;
diff --git a/Main/Manager/ResManager.cs b/Main/Manager/ResManager.cs
index 03e49f3..d5f3d4d 100644
--- a/Main/Manager/ResManager.cs
+++ b/Main/Manager/ResManager.cs
@@ -7,6 +7,8 @@
using LitJson;
using System.IO;
using UnityEngine.Networking;
+using UnityEngine.Video;
+
#if UNITY_EDITOR
using UnityEditor;
@@ -61,6 +63,19 @@
}
}
+ private static readonly Dictionary<Type, string> fileExtensionDict = new Dictionary<Type, string>()
+ {
+ {typeof(GameObject), "prefab"},
+ {typeof(Sprite), "png"},
+ {typeof(Texture2D), "png"},
+ {typeof(Shader), "shader"},
+ {typeof(TextAsset), "txt"},
+ {typeof(AudioClip), "wav"},
+ {typeof(Font), "ttf"},
+ {typeof(Material), "mat"},
+ {typeof(VideoClip), "mp4"},
+ {typeof(SpriteAtlas), "spriteatlasv2"},
+ };
public void Init()
@@ -75,22 +90,8 @@
private string GetExtension(Type type)
{
- if (type == typeof(GameObject))
- return ".prefab";
- else if (type == typeof(Sprite))
- return ".png";
- else if (type == typeof(Texture2D))
- return ".png";
- else if (type == typeof(Shader))
- return ".shader";
- else if (type == typeof(TextAsset))
- return ".txt";
- else if (type == typeof(AudioClip))
- return ".wav";
- else if (type == typeof(Font))
- return ".ttf";
- else if (type == typeof(Material))
- return ".mat";
+ if (fileExtensionDict.TryGetValue(type, out string extension))
+ return "." + extension;
else
{
Debug.LogErrorFormat("GetExtension() => 涓嶆敮鎸佺殑璧勬簮绫诲瀷: {0}.", type.Name);
@@ -125,32 +126,34 @@
public T LoadAsset<T> (string directory, string name) where T : UnityEngine.Object
{
T asset = null;
+
+ // 鐗规畩澶勭悊 鍥犱负鏈変竴灞傚浘闆嗙殑鍏崇郴 directory瑕佷紶鍏ョ殑搴旇鏄痑tlas鐨勫悕瀛�
+ if (typeof(T) == typeof(Sprite))
+ {
+ return LoadSprite(directory, name) as T;
+ }
+
+ return LoadAssetInternal<T>(directory, name);
+ }
+
+ private T LoadAssetInternal<T>(string directory, string name) where T : UnityEngine.Object
+ {
+ T asset = null;
+
+ var path = string.Concat($"Assets/ResourcesOut/{directory}/{name}", GetExtension(typeof(T))).Replace("//", "/");
+
+ if (AssetSource.uiFromEditor)
+ {
#if UNITY_EDITOR
- var path = string.Concat($"Assets/ResourcesOut/{directory}/{name}", GetExtension(typeof(T)));
-
- // 鎵句笉鍒版枃浠舵椂锛屽皾璇曞湪鍐呴儴缁х画鎵�
- if (!File.Exists(path))
- {
- path = GetRelativePath(FindFilePath(directory, name + GetExtension(typeof(T))));
-
- if (string.IsNullOrEmpty(path))
- {
- Debug.LogErrorFormat("LoadAsset() => 鍔犺浇涓嶅埌璧勬簮: {1} {0}." + path, name, directory);
- return asset;
- }
- }
-
- asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
-#else
- //TODO YYL ASSET BUNDLE閮ㄥ垎瑕侀噸鍐欏鐞嗕竴涓�
- if (prefabBundle == null)
- {
- // string _path = GetAssetFilePath("builtin/prefabs");
- string _path = GetAssetFilePath($"builtin/{directory}");
- prefabBundle = AssetBundle.LoadFromFile(_path);
- }
- asset = prefabBundle.LoadAsset(name) as t;
+ asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
#endif
+ }
+ else
+ {
+ var assetInfo = new AssetInfo(directory.ToLower(), name.ToLower());
+ asset = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(T)) as T;
+ }
+
if (asset == null)
{
Debug.LogErrorFormat("LoadAsset() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
@@ -159,11 +162,30 @@
return asset;
}
-
-
- public void UnloadAsset(string assetBundleName)
+ private Sprite LoadSprite(string atlasName, string spriteName)
{
-
+#if !UNITY_EDITOR
+ SpriteAtlas atlas = LoadAsset<SpriteAtlas>("Sprite", atlasName);
+ return atlas.GetSprite(spriteName);
+#else
+ // 缂栬緫鍣ㄤ笅鍙互鐩存帴鍔犺浇娌″暐闂
+ return LoadAssetInternal<Sprite>("Sprite/" + atlasName, spriteName);
+#endif
+ }
+
+ public void UnloadAsset(string assetBundleName, string assetName)
+ {
+ if (AssetSource.uiFromEditor)
+ return;
+
+ AssetBundleUtility.Instance.UnloadAsset(assetBundleName, assetName);
+ }
+
+ public void UnloadAssetBundle(string assetBundleName, bool unloadAllLoadedObjects, bool includeDependenice)
+ {
+ if (AssetSource.uiFromEditor)
+ return;
+ AssetBundleUtility.Instance.UnloadAssetBundle(assetBundleName, unloadAllLoadedObjects, includeDependenice);
}
public string GetAssetFilePath(string _assetKey)
diff --git a/Main/Message.meta b/Main/Message.meta
deleted file mode 100644
index 0aaf106..0000000
--- a/Main/Message.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 23097aa976ae3cf448f09b0f632e5316
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Main/ResModule/GameObjectPoolManager.cs b/Main/ResModule/GameObjectPoolManager.cs
deleted file mode 100644
index eec9c1e..0000000
--- a/Main/ResModule/GameObjectPoolManager.cs
+++ /dev/null
@@ -1,637 +0,0 @@
-锘�// using System.Collections.Generic;
-// using UnityEngine;
-// using System;
-
-
-
-// public class GameObjectPoolManager : SingletonMonobehaviour<GameObjectPoolManager>
-// {
-// #if UNITY_EDITOR
-// private Dictionary<int, DebugItem> m_DebugInstIDDict = null;
-// #endif
-// private Dictionary<int, GameObjectPool> m_PoolDict = null;
-
-// // 涓嶉渶瑕侀攢姣佺殑瀵硅薄鍒楄〃
-// private List<int> dontDestoryGoInstIDList = null;
-
-// private Transform m_TargetContainer;
-
-// public void Initialize()
-// {
-// if (m_PoolDict == null)
-// {
-// m_PoolDict = new Dictionary<int, GameObjectPool>();
-// }
-
-// if (!m_TargetContainer)
-// {
-// m_TargetContainer = new GameObject("Container").transform;
-// m_TargetContainer.SetParent(transform);
-// }
-
-// if (dontDestoryGoInstIDList == null)
-// {
-// dontDestoryGoInstIDList = new List<int>();
-// }
-
-// #if UNITY_EDITOR
-// if (m_DebugInstIDDict == null)
-// {
-// m_DebugInstIDDict = new Dictionary<int, DebugItem>();
-// }
-// #endif
-// }
-
-// public void AddDontDestroyGoInstID(int id)
-// {
-// if (!dontDestoryGoInstIDList.Contains(id))
-// {
-// dontDestoryGoInstIDList.Add(id);
-// }
-// }
-
-// public bool ExistPool(GameObject prefab)
-// {
-// if (prefab == null)
-// {
-// return false;
-// }
-
-// if (m_PoolDict.ContainsKey(prefab.GetInstanceID()))
-// {
-// return true;
-// }
-
-// return false;
-// }
-
-// public GameObjectPool RequestPool(GameObject prefab)
-// {
-// if (prefab == null)
-// {
-// return null;
-// }
-
-// int _prefabInstanceId = prefab.GetInstanceID();
-
-// GameObjectPool _pool = null;
-// if (m_PoolDict.TryGetValue(_prefabInstanceId, out _pool))
-// {
-// return _pool;
-// }
-
-// _pool = new GameObjectPool(prefab);
-// m_PoolDict[_prefabInstanceId] = _pool;
-
-// return _pool;
-// }
-
-
-// public void CacheGameObject(GameObject prefab, int count, bool _prefabActive)
-// {
-// if (prefab == null)
-// {
-// return;
-// }
-
-// RequestPool(prefab).Cache(count, _prefabActive);
-// }
-
-// public GameObject RequestGameObject(GameObject prefab)
-// {
-// if (prefab == null)
-// {
-// return null;
-// }
-
-// return RequestPool(prefab).Request();
-// }
-
-// public GameObject RequestEmptyJY()
-// {
-// var _prefab = InstanceResourcesLoader.LoadEmptyJY();
-// if (!_prefab)
-// {
-// return null;
-// }
-
-// var _pool = RequestPool(_prefab);
-// _pool.assetName = InstanceResourcesLoader.emptyJyName;
-// _pool.assetBundleName = "gmodels/prefab_race_jy";
-
-// return _pool.Request();
-// }
-
-// public void ReleaseEmptyJY(GameObject go)
-// {
-// var _prefab = InstanceResourcesLoader.LoadEmptyJY();
-// if (!_prefab)
-// {
-// return;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// if (_pool != null)
-// {
-// _pool.Release(go);
-// }
-// }
-
-// public GameObject RequestDefaultPet()
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[2][0],
-// GeneralDefine.ModeDefaultConfig[2][1]);
-
-// if (!_prefab)
-// {
-// return null;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// _pool.assetName = GeneralDefine.ModeDefaultConfig[2][1];
-// _pool.assetBundleName = GeneralDefine.ModeDefaultConfig[2][0];
-
-// return _pool.Request();
-// }
-
-// public GameObject RequestDefaultFightNpc()
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[1][0],
-// GeneralDefine.ModeDefaultConfig[1][1]);
-
-// if (!_prefab)
-// {
-// return null;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// _pool.assetName = GeneralDefine.ModeDefaultConfig[1][1];
-// _pool.assetBundleName = GeneralDefine.ModeDefaultConfig[1][0];
-
-// return _pool.Request();
-// }
-
-// public GameObject RequestDefaultFuncNpc()
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[0][0],
-// GeneralDefine.ModeDefaultConfig[0][1]);
-
-// if (!_prefab)
-// {
-// return null;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// _pool.assetName = GeneralDefine.ModeDefaultConfig[0][1];
-// _pool.assetBundleName = GeneralDefine.ModeDefaultConfig[0][0];
-
-// return _pool.Request();
-// }
-
-// public void ReleaseDefaultPet(GameObject go)
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[2][0],
-// GeneralDefine.ModeDefaultConfig[2][1]);
-// if (!_prefab)
-// {
-// return;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// if (_pool != null)
-// {
-// _pool.Release(go);
-// }
-// }
-
-// public void ReleaseDefaultHorse(GameObject go)
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[3][0],
-// GeneralDefine.ModeDefaultConfig[3][1]);
-// if (!_prefab)
-// {
-// return;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// if (_pool != null)
-// {
-// _pool.Release(go);
-// }
-// }
-
-// public void ReleaseDefaultFightNPC(GameObject go)
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[1][0],
-// GeneralDefine.ModeDefaultConfig[1][1]);
-
-// if (!_prefab)
-// {
-// return;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// if (_pool != null)
-// {
-// _pool.Release(go);
-// }
-// }
-
-// public void ReleaseDefaultFuncNPC(GameObject go)
-// {
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(GeneralDefine.ModeDefaultConfig[0][0],
-// GeneralDefine.ModeDefaultConfig[0][1]);
-
-// if (!_prefab)
-// {
-// return;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// if (_pool != null)
-// {
-// _pool.Release(go);
-// }
-// }
-
-// public GameObject RequestNpcGameObject(int npcID)
-// {
-// string _assetName;
-// string _assetBundleName;
-
-// NPCConfig _m = NPCConfig.Get(npcID);
-
-// if (_m == null || _m.MODE.Equals("0"))
-// {
-// return null;
-// }
-
-// if (GAMgr.Instance.s_NpcID2Assetname.TryGetValue(npcID, out _assetName))
-// {
-// _assetBundleName = GAMgr.Instance.s_NpcID2BundleName[npcID];
-// }
-// else
-// {
-// _assetName = StringUtility.Contact(InstanceResourcesLoader.raceSuffix, _m.MODE);
-// _assetBundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, _assetName);
-// GAMgr.Instance.s_NpcID2Assetname[npcID] = _assetName;
-// GAMgr.Instance.s_NpcID2BundleName[npcID] = _assetBundleName;
-// }
-
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(_assetBundleName, _assetName);
-
-// if (!_prefab)
-// {
-// return null;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-
-// _pool.assetBundleName = _assetBundleName;
-// _pool.assetName = _assetName;
-
-// return _pool.Request();
-// }
-
-// public void ReleaseGameObject(GameObject prefab, GameObject go)
-// {
-// GameObjectPool _pool = RequestPool(prefab);
-// if (_pool == null)
-// {
-// return;
-// }
-// _pool.Release(go);
-// }
-
-// public void Release(GameObject prefab)
-// {
-// int _prefabInstanceId = prefab.GetInstanceID();
-
-// GameObjectPool _pool = null;
-// if (m_PoolDict.TryGetValue(_prefabInstanceId, out _pool))
-// {
-// _pool.Clear();
-
-// if (_pool.IsEmpty())
-// {
-// m_PoolDict.Remove(_pool.PrefabInstanceId);
-// }
-// }
-// }
-
-// public void UnLoadNPC(int npcID)
-// {
-// if (!AssetSource.mobFromEditor)
-// {
-// string _assetName;
-// string _assetBundleName;
-
-// if (!GAMgr.Instance.s_NpcID2Assetname.TryGetValue(npcID, out _assetName))
-// {
-// return;
-// }
-// _assetBundleName = GAMgr.Instance.s_NpcID2BundleName[npcID];
-
-// if (!AssetBundleUtility.Instance.JudgeExistAssetBundle(_assetBundleName))
-// {
-// return;
-// }
-
-// GameObject _prefab = InstanceResourcesLoader.LoadMob(_assetBundleName, _assetName);
-
-// if (!_prefab)
-// {
-// return;
-// }
-
-// if (!ExistPool(_prefab))
-// {
-// return;
-// }
-
-// GameObjectPool _pool = RequestPool(_prefab);
-// _pool.Clear();
-// m_PoolDict.Remove(_pool.PrefabInstanceId);
-// }
-// }
-
-// public void UnLoadAll(bool force = false)
-// {
-// List<int> _removeList = new List<int>();
-// foreach (var _pool in m_PoolDict.Values)
-// {
-// if (GAMgr.Instance.needDestroyPrefabList.Contains(_pool.Prefab))
-// {
-// _pool.Clear();
-// _removeList.Add(_pool.PrefabInstanceId);
-// }
-// }
-
-// for (int i = 0; i < _removeList.Count; ++i)
-// {
-// m_PoolDict.Remove(_removeList[i]);
-// }
-// }
-
-// public class GameObjectPool
-// {
-// private GameObject m_Prefab = null;
-// public GameObject Prefab
-// {
-// get
-// {
-// return m_Prefab;
-// }
-// }
-// public int PrefabInstanceId
-// {
-// get; private set;
-// }
-
-// public List<GameObject> m_ActiveList = null;
-// private List<GameObject> m_FreeList = null;
-
-// Action<GameObject> releaseCallBack;
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// private Transform m_DebugContainer;
-// private Transform m_DebugActive;
-// private Transform m_DebugFree;
-// #endif
-
-// public string assetBundleName;
-// public string assetName;
-
-// internal protected GameObjectPool(GameObject prefab)
-// {
-// m_Prefab = prefab;
-// PrefabInstanceId = m_Prefab.GetInstanceID();
-// m_ActiveList = new List<GameObject>();
-// m_FreeList = new List<GameObject>();
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// m_DebugContainer = new GameObject(prefab.name).transform;
-// m_DebugActive = new GameObject("Active").transform;
-// m_DebugFree = new GameObject("Free").transform;
-// m_DebugActive.SetParent(m_DebugContainer);
-// m_DebugFree.SetParent(m_DebugContainer);
-// m_DebugContainer.SetParent(Instance.transform);
-// #endif
-// }
-
-// public void AddReleaseListener(Action<GameObject> _callBack)
-// {
-// releaseCallBack = _callBack;
-// }
-
-// public void RemoveReleaseListener()
-// {
-// releaseCallBack = null;
-// }
-
-// public void Cache(int count, bool _prefabActive)
-// {
-// GameObject _go;
-// for (int i = 0; i < count; ++i)
-// {
-// _go = Instantiate(m_Prefab, Constants.Special_Hide_Position, Quaternion.identity);
-// m_FreeList.Add(_go);
-// _go.transform.SetParent(Instance.m_TargetContainer);
-// _go.transform.position = Constants.Special_Hide_Position;
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-
-// DebugItem _debugItem = new GameObject(_go.GetInstanceID().ToString()).AddMissingComponent<DebugItem>();
-// _debugItem.transform.SetParent(m_DebugFree);
-// _debugItem.target = _go;
-// Instance.m_DebugInstIDDict[_go.GetInstanceID()] = _debugItem;
-// #endif
-// var animator = _go.GetComponent<Animator>();
-// if (animator != null)
-// {
-// animator.enabled = false;
-// }
-// _go.SetActive(_prefabActive);
-// }
-// }
-
-// public GameObject Request()
-// {
-// GameObject _go = null;
-
-// while (m_FreeList.Count > 0)
-// {
-// if (m_FreeList[0] != null)
-// {
-// _go = m_FreeList[0];
-
-// m_ActiveList.Add(_go);
-// m_FreeList.RemoveAt(0);
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// if (Instance.m_DebugInstIDDict.ContainsKey(_go.GetInstanceID()))
-// {
-// DebugItem _debugItem = Instance.m_DebugInstIDDict[_go.GetInstanceID()];
-// _debugItem.transform.SetParent(m_DebugActive);
-// }
-// #endif
-// break;
-// }
-// else
-// {
-// m_FreeList.RemoveAt(0);
-// }
-// }
-
-// if (_go == null)
-// {
-// _go = Instantiate(m_Prefab, Constants.Special_Hide_Position, Quaternion.identity);
-// m_ActiveList.Add(_go);
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// DebugItem _debugItem = new GameObject(_go.GetInstanceID().ToString()).AddMissingComponent<DebugItem>();
-// _debugItem.transform.SetParent(m_DebugActive);
-// _debugItem.target = _go;
-// Instance.m_DebugInstIDDict[_go.GetInstanceID()] = _debugItem;
-// #endif
-// }
-
-// _go.transform.SetParent(null);
-// _go.transform.localScale = Vector3.one;
-
-// return _go;
-// }
-
-// public void Release(GameObject go)
-// {
-// if (go == null)
-// {
-// return;
-// }
-// if (m_ActiveList.Contains(go))
-// {
-// m_ActiveList.Remove(go);
-// }
-// if (m_FreeList.Contains(go))
-// {
-// return;
-// }
-
-// m_FreeList.Add(go);
-// go.transform.SetParent(Instance.m_TargetContainer);
-// go.transform.position = Constants.Special_Hide_Position;
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// if (Instance.m_DebugInstIDDict.ContainsKey(go.GetInstanceID()))
-// {
-// DebugItem _debugItem = Instance.m_DebugInstIDDict[go.GetInstanceID()];
-// _debugItem.transform.SetParent(m_DebugFree);
-// }
-// #endif
-
-// if (releaseCallBack != null)
-// {
-// releaseCallBack(go);
-// }
-// }
-
-// public void ReleaseAll()
-// {
-// for (int i = m_ActiveList.Count - 1; i >= 0; i--)
-// {
-// var _go = m_ActiveList[i];
-// m_ActiveList.Remove(_go);
-
-// if (!m_FreeList.Contains(_go))
-// {
-// m_FreeList.Add(_go);
-// }
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// DebugItem _debugItem = Instance.m_DebugInstIDDict[_go.GetInstanceID()];
-// _debugItem.transform.SetParent(m_DebugFree);
-// #endif
-// _go.transform.SetParent(Instance.m_TargetContainer);
-// _go.transform.position = Constants.Special_Hide_Position;
-
-// if (releaseCallBack != null)
-// {
-// releaseCallBack(_go);
-// }
-// }
-// }
-
-// public void Clear()
-// {
-// for (int i = m_ActiveList.Count - 1; i >= 0; --i)
-// {
-// if (m_ActiveList[i] == null
-// || Instance.dontDestoryGoInstIDList.Contains(m_ActiveList[i].GetInstanceID()))
-// continue;
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// Destroy(Instance.m_DebugInstIDDict[m_ActiveList[i].GetInstanceID()].gameObject);
-// #endif
-// Destroy(m_ActiveList[i]);
-// m_ActiveList.RemoveAt(i);
-// }
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// if (m_ActiveList.Count != 0)
-// {
-// Debug.LogWarningFormat("{0} 姹犳竻鐞嗗悗, 杩樻湁 {1} 涓椿璺冨璞�. ", m_Prefab.name, m_ActiveList.Count);
-// for (int i = 0; i < m_ActiveList.Count; ++i)
-// {
-// Debug.LogWarningFormat(" |-- {0}", m_ActiveList[i].name);
-// }
-// }
-// #endif
-
-// for (int i = m_FreeList.Count - 1; i >= 0; --i)
-// {
-// if (m_FreeList[i] == null
-// || Instance.dontDestoryGoInstIDList.Contains(m_FreeList[i].GetInstanceID()))
-// continue;
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// Destroy(Instance.m_DebugInstIDDict[m_FreeList[i].GetInstanceID()].gameObject);
-// #endif
-// Destroy(m_FreeList[i]);
-// m_FreeList.RemoveAt(i);
-// }
-
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// if (m_FreeList.Count != 0)
-// {
-// Debug.LogWarningFormat("{0} 姹犳竻鐞嗗悗, 杩樻湁 {1} 涓┖闂插璞�. ", m_Prefab.name, m_FreeList.Count);
-// for (int i = 0; i < m_FreeList.Count; ++i)
-// {
-// Debug.LogWarningFormat(" |-- {0}", m_FreeList[i].name);
-// }
-// }
-// #endif
-// if (IsEmpty())
-// {
-// m_Prefab = null;
-// #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
-// Destroy(m_DebugContainer.gameObject);
-// #endif
-// }
-
-// if (!string.IsNullOrEmpty(assetBundleName) && !string.IsNullOrEmpty(assetName))
-// {
-// InstanceResourcesLoader.UnloadAsset(assetBundleName, assetName);
-// }
-// }
-
-// public bool IsEmpty()
-// {
-// return m_ActiveList.Count == 0 && m_FreeList.Count == 0;
-// }
-// }
-// }
diff --git a/Main/ResModule/GameObjectPoolManager.cs.meta b/Main/ResModule/GameObjectPoolManager.cs.meta
deleted file mode 100644
index 9741ee8..0000000
--- a/Main/ResModule/GameObjectPoolManager.cs.meta
+++ /dev/null
@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: 27d561bd4736c5d4c997bf253c83d47e
-timeCreated: 1502507579
-licenseType: Free
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Main/ResModule/UILoader.cs b/Main/ResModule/UILoader.cs
index b965037..68d1677 100644
--- a/Main/ResModule/UILoader.cs
+++ b/Main/ResModule/UILoader.cs
@@ -7,368 +7,56 @@
using UnityEngine.U2D;
-// public class UILoader
-// {
-// readonly static string PREFAB_EXTERSION = ".prefab";
-// readonly static string SPRITE_EXTERSION = ".png";
-// readonly static string Spriteatlas_EXTERSION = ".spriteatlasv2";
+public class UILoader
+{
+ public static GameObject LoadWindow(string name)
+ {
+ return ResManager.Instance.LoadAsset<GameObject>("UI", name);
+ }
-// public static GameObject LoadWindow(string name)
-// {
-// GameObject window = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var isPriority = false;//PriorityWindowConfig.Get().priorityWindows.Contains(name);
+ public static GameObject LoadPrefab(string _name)
+ {
+ return ResManager.Instance.LoadAsset<GameObject>("Prefab", _name);
+ }
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX : ResourcesPath.UI_WINDOW_SUFFIX, "/",
-// name,
-// PREFAB_EXTERSION);
+ public static void UnLoadPrefab(string _assetName)
+ {
+ ResManager.Instance.UnloadAsset("Prefab", _assetName);
+ }
-// window = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// #endif
-// }
-// else
-// {
-// // var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(name);
-// var bundleName = "ui/window";
+ public static Sprite LoadSprite(string _iconKey)
+ {
+ var iconConfig = IconConfig.Get(_iconKey);
+ if (iconConfig == null)
+ {
+ return null;
+ }
-// var assetInfo = new AssetInfo(bundleName, name);
+ return LoadSprite(iconConfig.folder, iconConfig.sprite);
+ }
-// window = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
-// }
+ public static Sprite LoadSprite(string _folder, string _file)
+ {
+ return ResManager.Instance.LoadAsset<Sprite>("Sprite/" + _folder, _file);
+ }
-// if (window == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadWindow() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
-// }
+ public static void UnLoadSprite(string _iconKey)
+ {
+ var iconConfig = IconConfig.Get(_iconKey);
+ if (iconConfig != null)
+ {
+ var bundleName = StringUtility.Contact("Sprite/", iconConfig.folder);
+ ResManager.Instance.UnloadAsset(bundleName, iconConfig.sprite);
+ }
+ }
-// return window;
-// }
+ public static Font LoadFont(string _fontName)
+ {
+ return ResManager.Instance.LoadAsset<Font>("Font", _fontName);
+ }
-// public static void LoadWindowAsync(string _name, Action<bool, UnityEngine.Object> _callBack)
-// {
-// GameObject window = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name);
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// isPriority ? ResourcesPath.UI_PRIORITYWINDOW_SUFFIX : ResourcesPath.UI_WINDOW_SUFFIX, "/",
-// _name,
-// PREFAB_EXTERSION);
-
-// window = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// if (_callBack != null)
-// {
-// _callBack(window != null, window);
-// }
-// #endif
-// }
-// else
-// {
-// var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_name);
-// var bundleName = isPriority ? StringUtility.Contact("ui/prioritywindow/", _name) : "ui/window";
-// var assetInfo = new AssetInfo(bundleName, _name);
-
-// AssetBundleUtility.Instance.Co_LoadAsset(assetInfo, _callBack);
-// }
-// }
-
-// public static void UnLoadWindowAsset(string _assetName)
-// {
-// if (!AssetSource.uiFromEditor)
-// {
-// var isPriority = PriorityWindowConfig.Get().priorityWindows.Contains(_assetName);
-// var bundleName = isPriority ? StringUtility.Contact("ui/prioritywindow/", _assetName) : "ui/window";
-
-// AssetBundleUtility.Instance.UnloadAsset(bundleName, _assetName);
-// }
-// }
-
-// public static void UnLoadPriorityWindow(string windowName)
-// {
-// if (!AssetSource.uiFromEditor)
-// {
-// var assetBundleName = StringUtility.Contact("ui/prioritywindow/", windowName.ToLower());
-// AssetBundleUtility.Instance.UnloadAssetBundle(assetBundleName, true, false);
-
-// switch (windowName)
-// {
-// case "LoginWin":
-// AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/login", true, false);
-// break;
-// case "SelectRoleWin":
-// case "CreateRoleWin":
-// AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/createrole", true, false);
-// break;
-// }
-// }
-// }
-
-// public static GameObject LoadPrefab(string _name)
-// {
-// GameObject prefab = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// ResourcesPath.UI_PREFAB_SUFFIX, "/",
-// _name,
-// PREFAB_EXTERSION);
-
-// prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// #endif
-// }
-// else
-// {
-// var bundleName = ResourcesPath.UI_PREFAB_SUFFIX.ToLower();
-// var assetInfo = new AssetInfo(bundleName, _name);
-
-// prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
-// }
-
-// if (prefab == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadPrefab() => 鍔犺浇涓嶅埌璧勬簮: {0}.", _name);
-// }
-
-// return prefab;
-// }
-
-// public static void UnLoadPrefab(string _assetName)
-// {
-// if (!AssetSource.uiFromEditor)
-// {
-// AssetBundleUtility.Instance.UnloadAsset("ui/prefab", _assetName);
-// }
-// }
-
-// public static Sprite LoadSprite(string _iconKey)
-// {
-// var iconConfig = IconConfig.Get(_iconKey);
-// if (iconConfig == null)
-// {
-// return null;
-// }
-
-// return LoadSprite(iconConfig.folder, iconConfig.sprite);
-// }
-
-// public static Sprite LoadSprite(string _folder, string _file)
-// {
-// var folder = _folder;
-// var file = _file;
-
-// Sprite sprite = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var relativePath = folder;
-// var rootPath = ResourcesPath.UI_SPRITE_SUFFIX;
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// rootPath, "/",
-// relativePath,
-// Spriteatlas_EXTERSION);
-
-// var spriteAtlas = UnityEditor.AssetDatabase.LoadAssetAtPath<SpriteAtlas>(path);
-// sprite = spriteAtlas.GetSprite(file);
-// #endif
-// }
-// else
-// {
-// var bundleName = StringUtility.Contact("ui/sprite/", folder.ToLower());
-// //var assetInfo = new AssetInfo(bundleName, folder);
-
-// //var spriteAtlas = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(SpriteAtlas)) as SpriteAtlas;
-// //sprite = spriteAtlas?.GetSprite(_file);
-// var assetInfo = new AssetInfo(bundleName, file);
-
-// sprite = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Sprite)) as Sprite;
-// }
-
-// if (sprite == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadSprite() => 鍔犺浇涓嶅埌璧勬簮: {0}.", file);
-// }
-
-// return sprite;
-// }
-
-// public static void UnLoadSprite(string _iconKey)
-// {
-// if (!AssetSource.uiFromEditor)
-// {
-// var iconConfig = IconConfig.Get(_iconKey);
-// if (iconConfig != null)
-// {
-// var bundleName = StringUtility.Contact("ui/sprite/", iconConfig.folder.ToLower());
-// AssetBundleUtility.Instance.UnloadAsset(bundleName, iconConfig.sprite);
-// }
-// }
-
-// }
-
-// public static Font LoadFont(string _fontName)
-// {
-// Font font = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var rootPath = ResourcesPath.UI_FONT_SUFFIX;
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, rootPath, "/", _fontName, ".ttf");
-// font = UnityEditor.AssetDatabase.LoadAssetAtPath<Font>(path);
-// #endif
-// }
-// else
-// {
-// var assetInfo = new AssetInfo("ui/font", _fontName);
-// font = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Font)) as Font;
-// }
-
-// if (font == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadFont() => 鍔犺浇涓嶅埌璧勬簮: {0}.", _fontName);
-// }
-
-// return font;
-// }
-
-// public static void UnLoadFont(string _fontName)
-// {
-// if (!AssetSource.uiFromEditor)
-// {
-// AssetBundleUtility.Instance.UnloadAsset("ui/font", _fontName);
-// }
-// }
-
-// public static GameObject LoadTreasure(string folder, string name)
-// {
-// GameObject prefab = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// "UI/Treasure/", folder, "/",
-// name,
-// PREFAB_EXTERSION);
-
-// prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// #endif
-// }
-// else
-// {
-// var bundleName = StringUtility.Contact("ui/treasure/", folder).ToLower();
-// var assetInfo = new AssetInfo(bundleName, name);
-
-// prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
-// }
-
-// if (prefab == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadPrefab() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
-// }
-
-// return prefab;
-// }
-
-// public static void UnLoadTreasure(string folder, string _assetName)
-// {
-// if (!AssetSource.uiFromEditor)
-// {
-// AssetBundleUtility.Instance.UnloadAsset(StringUtility.Contact("ui/treasure/", folder).ToLower(), _assetName);
-// }
-// }
-
-// public static GameObject LoadFaqi(string pathName, string name)
-// {
-// GameObject prefab = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// //"UI/Treasure/", folder, "/",
-// pathName,
-// name,
-// PREFAB_EXTERSION);
-
-// prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// #endif
-// }
-// else
-// {
-// var bundleName = pathName; //StringUtility.Contact("ui/treasure/", folder).ToLower();
-// var assetInfo = new AssetInfo(bundleName, name);
-
-// prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
-// }
-
-// if (prefab == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadFaqi() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
-// }
-
-// return prefab;
-// }
-
-
-// public static GameObject LoadGodWeapon(string _name)
-// {
-// GameObject prefab = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// "UI/GodWeapon/",
-// _name,
-// PREFAB_EXTERSION);
-
-// prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// #endif
-// }
-// else
-// {
-// var bundleName = "ui/godweapon";
-// var assetInfo = new AssetInfo(bundleName, _name);
-// prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
-// }
-
-// if (prefab == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadGodWeapon() => 鍔犺浇涓嶅埌璧勬簮: {0}.", _name);
-// }
-
-// return prefab;
-// }
-
-// public static GameObject LoadBossShow(string _name)
-// {
-// GameObject prefab = null;
-// if (AssetSource.uiFromEditor)
-// {
-// #if UNITY_EDITOR
-// var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
-// "UI/BossShow/",
-// _name,
-// PREFAB_EXTERSION);
-
-// prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-// #endif
-// }
-// else
-// {
-// var bundleName = "ui/bossshow";
-// var assetInfo = new AssetInfo(bundleName, _name);
-// prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject;
-// }
-
-// if (prefab == null)
-// {
-// Debug.LogErrorFormat("UILoader.LoadBossShow() => 鍔犺浇涓嶅埌璧勬簮: {0}.", _name);
-// }
-
-// return prefab;
-// }
-
-// }
+ public static void UnLoadFont(string _fontName)
+ {
+ ResManager.Instance.UnloadAsset("Font", _fontName);
+ }
+}
diff --git a/Main/System/KnapSack/Logic/CommonGetItemWin.cs b/Main/System/KnapSack/Logic/CommonGetItemWin.cs
index 271511f..7e7f3d6 100644
--- a/Main/System/KnapSack/Logic/CommonGetItemWin.cs
+++ b/Main/System/KnapSack/Logic/CommonGetItemWin.cs
@@ -21,19 +21,6 @@
sureBtn.SetListener(() => UIManager.Instance.CloseWindow<CommonGetItemWin>());
}
- public override void HandleOpen()
- {
- base.HandleOpen();
- Debug.Log("鎵撳紑閫氱敤鑾峰緱鐗╁搧绐楀彛");
- Refresh();
- }
-
- public override void HandleClose()
- {
- base.HandleClose();
- Debug.Log("鍏抽棴閫氱敤鑾峰緱鐗╁搧绐楀彛");
- }
-
public override void Refresh()
{
base.Refresh();
@@ -42,6 +29,7 @@
protected override void OnPreOpen()
{
+ Refresh();
ItemLogicUtility.Instance.OnGetItemShowEvent += OnGetItemShowEvent;
scroller.OnRefreshCell += OnRefreshCell;
desc.SetActive(!string.IsNullOrEmpty(ItemLogicUtility.Instance.getItemInfo));
diff --git a/Main/System/Login/LoginWin.cs b/Main/System/Login/LoginWin.cs
index 90c2d32..faad4c2 100644
--- a/Main/System/Login/LoginWin.cs
+++ b/Main/System/Login/LoginWin.cs
@@ -79,9 +79,9 @@
});
}
- public override void HandleOpen()
+ protected override void OnPreOpen()
{
- base.HandleOpen();
+ base.OnPreOpen();
Debug.Log("鎵撳紑鐧诲綍绐楀彛");
@@ -102,9 +102,9 @@
});
}
- public override void HandleClose()
+ protected override void OnPreClose()
{
- base.HandleClose();
+ base.OnPreClose();
Debug.Log("鍏抽棴鐧诲綍绐楀彛");
ServerListCenter.Instance.serverSelectEvent -= OnServerChange;
ServerListCenter.Instance.onServerListRefreshEvent -= OnServerListRefresh;
diff --git a/Main/System/Message/ImgAnalysis.cs b/Main/System/Message/ImgAnalysis.cs
index 8d6a9a8..8923bb5 100644
--- a/Main/System/Message/ImgAnalysis.cs
+++ b/Main/System/Message/ImgAnalysis.cs
@@ -189,8 +189,7 @@
if (presentImgInfo.IsFace) return;
if (IconConfig.isInit)
{
- presentImgInfo.sprite = ResManager.Instance.LoadAsset<Sprite>("Sprite", presentImgInfo.spriteName);
- // presentImgInfo.sprite = UILoader.LoadSprite(presentImgInfo.spriteName);
+ presentImgInfo.sprite = UILoader.LoadSprite(presentImgInfo.spriteName);
}
if (presentImgInfo.sprite != null)
diff --git a/Main/UI/LoadingWin.cs b/Main/UI/LoadingWin.cs
index 4f293e7..a56b318 100644
--- a/Main/UI/LoadingWin.cs
+++ b/Main/UI/LoadingWin.cs
@@ -23,16 +23,16 @@
progressText = transform.Find("Text_Progress").GetComponent<Text>();
}
- public override void HandleOpen()
+ protected override void OnPreOpen()
{
- base.HandleOpen();
+ base.OnPreOpen();
currentProgress = targetProgress = 0;
Refresh();
}
- public override void HandleClose()
+ protected override void OnPreClose()
{
- base.HandleClose();
+ base.OnPreClose();
}
public override void Refresh()
diff --git a/Main/UI/UIBase.cs b/Main/UI/UIBase.cs
index 7e0e1eb..9aa46cb 100644
--- a/Main/UI/UIBase.cs
+++ b/Main/UI/UIBase.cs
@@ -209,7 +209,7 @@
}
// 鎵撳紑UI
- public virtual void HandleOpen()
+ public void HandleOpen()
{
OnPreOpen();
// 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄
@@ -228,7 +228,7 @@
}
// 鍏抽棴UI - 淇敼鍚庣殑鏂规硶
- public virtual void HandleClose()
+ public void HandleClose()
{
// 濡傛灉宸茬粡鍦ㄥ叧闂繃绋嬩腑锛岀洿鎺ヨ繑鍥�
if (isClosing) return;
@@ -272,7 +272,7 @@
public virtual void CloseWindow()
{
- UIManager.Instance.CloseWindow(this);
+ UIManager.Instance.CloseWindow(this, false);
}
// 鍒锋柊UI
@@ -309,22 +309,29 @@
/// <param name="autoDestroy">鏄惁鑷姩閿�姣侊紝榛樿涓簍rue</param>
/// <param name="destroyDelay">鑷姩閿�姣佸欢杩熸椂闂达紝榛樿涓�5绉�</param>
/// <returns>鐗规晥娓告垙瀵硅薄</returns>
- public async UniTask<GameObject> PlayUIEffect(string effectName, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f)
+ public async UniTask<GameObject> PlayUIEffect(int id, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f)
{
// 浣跨敤榛樿鍊�
if (parent == null) parent = transform;
+ EffectConfig effectCfg = EffectConfig.Get(id);
+
+ if (null == effectCfg)
+ {
+ return null;
+ }
+
// 鍔犺浇鐗规晥璧勬簮
- GameObject effectPrefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect", effectName);
+ var effectPrefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectCfg.packageName, effectCfg.fxName);
if (effectPrefab == null)
{
- Debug.LogError($"鍔犺浇UI鐗规晥澶辫触: {effectName}");
+ Debug.LogError($"鍔犺浇UI鐗规晥澶辫触: {effectCfg.packageName}");
return null;
}
// 瀹炰緥鍖栫壒鏁�
GameObject effectObj = Instantiate(effectPrefab, parent);
- effectObj.name = $"Effect_{effectName}";
+ effectObj.name = $"Effect_{effectCfg.packageName}";
// 娣诲姞鐗规晥绌块�忛樆鎸″櫒
EffectPenetrationBlocker blocker = effectObj.AddComponent<EffectPenetrationBlocker>();
diff --git a/Main/UI/UIManager.cs b/Main/UI/UIManager.cs
index 5abeecc..7babf03 100644
--- a/Main/UI/UIManager.cs
+++ b/Main/UI/UIManager.cs
@@ -31,6 +31,9 @@
// UI瀛楀吀锛屽瓨鍌ㄦ墍鏈夊凡鍔犺浇鐨刄I锛岄敭涓篣I鍚嶇О锛屽�间负UI瀹炰緥
private Dictionary<string, List<UIBase>> uiDict = new Dictionary<string, List<UIBase>>();
+ // 瀛樺偍鍏抽棴浣嗘湭閿�姣佺殑UI锛岄敭涓篣I鍚嶇О锛屽�间负UI瀹炰緥
+ private Dictionary<string, List<UIBase>> closedUIDict = new Dictionary<string, List<UIBase>>();
+
// UI鏍堬紝鐢ㄤ簬绠$悊UI鐨勬樉绀洪『搴�
private Stack<UIBase> uiStack = new Stack<UIBase>();
@@ -91,56 +94,33 @@
// 濡傛灉鍦烘櫙涓病鏈塙I鏍硅妭鐐癸紝鍒欏垱寤轰竴涓�
if (root == null)
{
- root = new GameObject("UIRoot");
-
- // 娣诲姞DontDestroyOnLoad缁勪欢锛岀‘淇漊I鏍硅妭鐐瑰湪鍦烘櫙鍒囨崲鏃朵笉琚攢姣�
- GameObject.DontDestroyOnLoad(root);
-
- // 鍒涘缓鍚勫眰绾ц妭鐐�
- GameObject staticNode = new GameObject("Static");
- GameObject bottomNode = new GameObject("Bottom");
- GameObject midNode = new GameObject("Mid");
- GameObject topNode = new GameObject("Top");
- GameObject systemNode = new GameObject("System");
-
- // 璁剧疆鐖惰妭鐐�
- staticNode.transform.SetParent(root.transform, false);
- bottomNode.transform.SetParent(root.transform, false);
- midNode.transform.SetParent(root.transform, false);
- topNode.transform.SetParent(root.transform, false);
- systemNode.transform.SetParent(root.transform, false);
-
+ root = GameObject.Instantiate(BuiltInLoader.LoadPrefab("UIRoot"));
+
if (root == null)
{
Debug.LogError("鏃犳硶鎵惧埌UI鏍硅妭鐐�");
return;
}
+
+ // 娣诲姞DontDestroyOnLoad缁勪欢锛岀‘淇漊I鏍硅妭鐐瑰湪鍦烘櫙鍒囨崲鏃朵笉琚攢姣�
+ GameObject.DontDestroyOnLoad(root);
}
uiRoot = root.transform;
uiRoot.position = Vector3.zero;
- // 鍒濆鍖栧悇灞傜骇鐨凾ransform
staticTrans = uiRoot.Find("Static");
bottomTrans = uiRoot.Find("Bottom");
midTrans = uiRoot.Find("Middle");
topTrans = uiRoot.Find("Top");
systemTrans = uiRoot.Find("System");
- // // 娣诲姞鍩虹Canvas
- // Canvas rootCanvas = root.AddComponent<Canvas>();
- // rootCanvas.renderMode = RenderMode.ScreenSpaceOverlay;
- // rootCanvas.sortingOrder = 0;
-
- // // 娣诲姞CanvasScaler
- // UnityEngine.UI.CanvasScaler scaler = root.AddComponent<UnityEngine.UI.CanvasScaler>();
- // scaler.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize;
- // scaler.referenceResolution = new Vector2(1920, 1080);
- // scaler.screenMatchMode = UnityEngine.UI.CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
- // scaler.matchWidthOrHeight = 1.0f;
-
- // // 娣诲姞GraphicRaycaster
- // root.AddComponent<UnityEngine.UI.GraphicRaycaster>();
+ layerTransformCache.Clear();
+ layerTransformCache.Add(UILayer.Static, staticTrans);
+ layerTransformCache.Add(UILayer.Bottom, bottomTrans);
+ layerTransformCache.Add(UILayer.Mid, midTrans);
+ layerTransformCache.Add(UILayer.Top, topTrans);
+ layerTransformCache.Add(UILayer.System, systemTrans);
}
#endregion
@@ -370,13 +350,13 @@
public void CheckAndCloseIdleUI()
{
// 濡傛灉娌℃湁UI锛岀洿鎺ヨ繑鍥�
- if (uiDict.Count == 0)
+ if (uiDict.Count == 0 && closedUIDict.Count == 0)
return;
// 鍒涘缓闇�瑕佸叧闂殑UI鍒楄〃
List<UIBase> uiToClose = new List<UIBase>();
- // 閬嶅巻鎵�鏈塙I
+ // 閬嶅巻鎵�鏈夋椿璺僓I
foreach (var uiList in uiDict.Values)
{
foreach (var ui in uiList)
@@ -385,6 +365,9 @@
if (ui.isPersistent)
continue;
+ if (ui.IsActive())
+ continue;
+
// 璁$畻UI绌洪棽鐨勫洖鍚堟暟
int idleRounds = currentRound - ui.lastUsedRound;
@@ -396,13 +379,53 @@
}
}
- // 鍏抽棴鎵�鏈夐渶瑕佸叧闂殑UI
+ // 閬嶅巻鎵�鏈夊叧闂殑UI
+ List<string> emptyKeys = new List<string>();
+ foreach (var kvp in closedUIDict)
+ {
+ string uiName = kvp.Key;
+ List<UIBase> uiList = kvp.Value;
+ List<UIBase> uiToRemove = new List<UIBase>();
+
+ foreach (var ui in uiList)
+ {
+ // 璁$畻UI绌洪棽鐨勫洖鍚堟暟
+ int idleRounds = currentRound - ui.lastUsedRound;
+
+ // 濡傛灉绌洪棽鍥炲悎鏁拌秴杩囨渶澶х┖闂插洖鍚堟暟锛屾坊鍔犲埌鍏抽棴鍒楄〃
+ if (idleRounds > ui.maxIdleRounds)
+ {
+ uiToClose.Add(ui);
+ uiToRemove.Add(ui);
+ }
+ }
+
+ // 浠庡叧闂垪琛ㄤ腑绉婚櫎闇�瑕侀攢姣佺殑UI
+ foreach (var ui in uiToRemove)
+ {
+ uiList.Remove(ui);
+ }
+
+ // 濡傛灉鍒楄〃涓虹┖锛岃褰曢渶瑕佷粠瀛楀吀涓Щ闄ょ殑閿�
+ if (uiList.Count == 0)
+ {
+ emptyKeys.Add(uiName);
+ }
+ }
+
+ // 浠庡瓧鍏镐腑绉婚櫎绌哄垪琛�
+ foreach (var key in emptyKeys)
+ {
+ closedUIDict.Remove(key);
+ }
+
+ // 閿�姣佹墍鏈夐渶瑕佸叧闂殑UI
foreach (var ui in uiToClose)
{
// 璁板綍鏃ュ織
- Debug.Log($"鍏抽棴闀挎椂闂存湭浣跨敤鐨刄I: {ui.uiName}, 绌洪棽鍥炲悎鏁�: {currentRound - ui.lastUsedRound}");
- // 鍏抽棴UI
- CloseWindow(ui);
+ Debug.Log($"閿�姣侀暱鏃堕棿鏈娇鐢ㄧ殑UI: {ui.uiName}, 绌洪棽鍥炲悎鏁�: {currentRound - ui.lastUsedRound}");
+ // 閿�姣乁I瀵硅薄
+ GameObject.Destroy(ui.gameObject);
}
}
@@ -525,8 +548,80 @@
// 鑾峰彇UI绫诲瀷鍚嶇О
string uiName = typeof(T).Name;
- // Debug.LogError("鎵撳紑ui " + uiName);
+ // 浼樺厛浠巆losedUIDict涓幏鍙�
+ if (closedUIDict.TryGetValue(uiName, out List<UIBase> closedUIList) && closedUIList.Count > 0)
+ {
+ T recycledUI = closedUIList[0] as T;
+ closedUIList.RemoveAt(0);
+
+ if (closedUIList.Count == 0)
+ {
+ closedUIDict.Remove(uiName);
+ }
+
+ recycledUI.gameObject.SetActive(true);
+
+ // 鑷姩璁剧疆鐖剁骇UI锛堝鏋滄湭鎸囧畾涓旀敮鎸佺埗瀛愬叧绯伙級
+ if (parentUI == null && recycledUI.supportParentChildRelation && uiStack.Count > 0)
+ {
+ // 鑾峰彇鏍堥《UI
+ UIBase topUI = uiStack.Peek();
+ // 濡傛灉鏍堥《UI涔熸敮鎸佺埗瀛愬叧绯讳笖涓嶆槸涓籙I锛屽垯灏嗗叾璁句负鐖剁骇
+ if (topUI != null && topUI.supportParentChildRelation && !topUI.isMainUI)
+ {
+ parentUI = topUI;
+ }
+ }
+
+ // 璁剧疆鐖剁骇UI
+ if (parentUI != null && recycledUI.supportParentChildRelation && !parentUI.isMainUI)
+ {
+ // 璁剧疆鐖跺瓙鍏崇郴
+ recycledUI.parentUI = parentUI;
+ if (parentUI.childrenUI == null)
+ {
+ // 鍒濆鍖栫埗绾I鐨勫瓙UI鍒楄〃
+ parentUI.childrenUI = new List<UIBase>();
+ }
+ // 娣诲姞鍒扮埗绾I鐨勫瓙UI鍒楄〃
+ parentUI.childrenUI.Add(recycledUI);
+ }
+
+ // 鏇存柊鍥炲悎鏁�
+ currentRound++;
+ // 璁剧疆UI鐨勬渶鍚庝娇鐢ㄥ洖鍚堟暟
+ recycledUI.lastUsedRound = currentRound;
+ // 鏇存柊鐖剁骇UI鐨勫洖鍚堟暟
+ UpdateParentUIRounds(recycledUI);
+
+ // 灏哢I娣诲姞鍒板瓧鍏镐腑
+ if (!uiDict.ContainsKey(uiName))
+ {
+ // 濡傛灉瀛楀吀涓笉瀛樺湪璇ョ被鍨嬬殑UI锛屽垱寤烘柊鍒楄〃
+ uiDict[uiName] = new List<UIBase>();
+ }
+ // 娣诲姞鍒癠I鍒楄〃
+ uiDict[uiName].Add(recycledUI);
+
+ // 灏哢I娣诲姞鍒版爤涓�
+ uiStack.Push(recycledUI);
+
+ // 鏇存柊UI鎺掑簭椤哄簭
+ UpdateUISortingOrder();
+
+ // 鎵撳紑UI
+ recycledUI.HandleOpen();
+ OnOpenWindow?.Invoke(recycledUI);
+
+ // 妫�鏌ュ苟鍏抽棴闀挎椂闂存湭浣跨敤鐨刄I
+ CheckAndCloseIdleUI();
+
+ return recycledUI;
+ }
+
+ // 濡傛灉closedUIDict涓病鏈夊彲鐢ㄧ殑UI瀹炰緥锛屽垯鍔犺浇鏂扮殑UI璧勬簮
+ // Debug.LogError("鎵撳紑ui " + uiName);
// 鍔犺浇UI璧勬簮
T ui = LoadUIResource<T>(uiName);
@@ -601,16 +696,16 @@
/// <summary>
/// 鍏抽棴UI
/// </summary>
- public void CloseWindow<T>() where T : UIBase
+ public void CloseWindow<T>(bool destroy = false) where T : UIBase
{
// 鑾峰彇UI绫诲瀷鍚嶇О
string uiName = typeof(T).Name;
- CloseWindow(uiName);
+ CloseWindow(uiName, destroy);
}
- public void CloseWindow(string uiName)
+ public void CloseWindow(string uiName, bool destroy = false)
{
// 妫�鏌I鏄惁瀛樺湪
if (!uiDict.ContainsKey(uiName) || uiDict[uiName].Count == 0)
@@ -624,13 +719,13 @@
UIBase ui = uiDict[uiName][0];
// 鍏抽棴UI
- CloseWindow(ui);
+ CloseWindow(ui, destroy);
}
/// <summary>
/// 鍏抽棴鎸囧畾鐨刄I瀹炰緥
/// </summary>
- public void CloseWindow(UIBase ui)
+ public void CloseWindow(UIBase ui, bool destroy = false)
{
// 妫�鏌I鏄惁涓虹┖
if (ui == null)
@@ -654,7 +749,7 @@
foreach (var childUI in childrenUI)
{
// 鍏抽棴瀛怳I
- CloseWindow(childUI);
+ CloseWindow(childUI, destroy);
}
// 浠庢爤涓Щ闄I
@@ -699,8 +794,23 @@
ui.HandleClose();
OnCloseWindow?.Invoke(ui);
- // 閿�姣乁I瀵硅薄
- GameObject.Destroy(ui.gameObject);
+ if (destroy)
+ {
+ // 閿�姣乁I瀵硅薄
+ GameObject.Destroy(ui.gameObject);
+ }
+ else
+ {
+ // 娣诲姞鍒癱losedUIDict
+ if (!closedUIDict.ContainsKey(uiName))
+ {
+ closedUIDict[uiName] = new List<UIBase>();
+ }
+ closedUIDict[uiName].Add(ui);
+
+ // 闅愯棌UI
+ ui.gameObject.SetActive(false);
+ }
// 鏇存柊UI鎺掑簭椤哄簭
UpdateUISortingOrder();
@@ -729,7 +839,7 @@
foreach (var ui in uiListCopy)
{
// 鍏抽棴UI瀹炰緥
- CloseWindow(ui);
+ CloseWindow(ui, false);
}
}
@@ -746,12 +856,13 @@
foreach (var ui in uiArray)
{
// 鍏抽棴UI
- CloseWindow(ui);
+ CloseWindow(ui, true);
}
// 娓呯┖UI瀛楀吀鍜屾爤
uiDict.Clear();
uiStack.Clear();
+ closedUIDict.Clear();
}
/// <summary>
diff --git a/Main/Utility/MaterialUtility.cs b/Main/Utility/MaterialUtility.cs
index 1fbe894..3044113 100644
--- a/Main/Utility/MaterialUtility.cs
+++ b/Main/Utility/MaterialUtility.cs
@@ -7,7 +7,7 @@
public static Material GetDefaultSpriteGrayMaterial()
{
- return ResManager.Instance.LoadAsset<Material>("Material", "SpriteGray");
+ return ResManager.Instance.LoadAsset<Material>("Materials", "SpriteGray");
}
public static Material GetInstantiatedSpriteGrayMaterial()
@@ -18,12 +18,12 @@
public static Material GetSmoothMaskGrayMaterial()
{
- return ResManager.Instance.LoadAsset<Material>("Material", "SmoothMaskGray");
+ return ResManager.Instance.LoadAsset<Material>("Materials", "SmoothMaskGray");
}
public static Material GetInstantiatedSpriteTwinkleMaterial()
{
- var material = ResManager.Instance.LoadAsset<Material>("Material", "Flash");
+ var material = ResManager.Instance.LoadAsset<Material>("Materials", "Flash");
return new Material(material);
}
@@ -32,14 +32,9 @@
return UnityEngine.UI.Image.defaultGraphicMaterial;
}
- public static Material GetUIBlurMaterial()
- {
- return ResManager.Instance.LoadAsset<Material>("Material", "GUIBlurMaterial");
- }
-
public static Material GetGUIRenderTextureMaterial()
{
- return ResManager.Instance.LoadAsset<Material>("Material", "UI_RenderTexture");
+ return ResManager.Instance.LoadAsset<Material>("Materials", "UI_RenderTexture");
}
public static void SetRenderSortingOrder(this GameObject root, int sortingOrder, bool includeChildren)
@@ -67,67 +62,8 @@
renderer.sortingOrder = sortingOrder;
}
}
-
}
-
- static Shader m_HeroShader;
- static Shader m_PlayerShader;
- static Shader heroShader {
- get {
- if (m_HeroShader == null)
- {
- m_HeroShader = Shader.Find("Character/Character,Emission,Flow_Hero");
- }
-
- if (m_HeroShader == null)
- {
- m_HeroShader = Shader.Find("Character/Character, Emission,Flow_Hero");
- }
-
- return m_HeroShader;
- }
- }
-
- static Shader playerShader {
- get {
- if (m_PlayerShader == null)
- {
- m_PlayerShader = Shader.Find("Character/Character,Emission,Flow");
- }
-
- if (m_PlayerShader == null)
- {
- m_PlayerShader = Shader.Find("Character/Character, Emission,Flow");
- }
-
- return m_PlayerShader;
- }
- }
-
- public static void SwitchXrayShader(Material _material, bool _isHero)
- {
- if (_material == null)
- {
- return;
- }
-
- if (_isHero)
- {
- if (_material.shader.name != "Character/Character,Emission,Flow_Hero" && _material.shader.name != "Character/Character, Emission,Flow_Hero")
- {
- _material.shader = heroShader;
- _material.SetColor("_XRayColor", new Color32(0, 107, 255, 255));
- }
- }
- else
- {
- if (_material.shader.name != "Character/Character, Emission,Flow" && _material.shader.name != "Character/Character,Emission,Flow")
- {
- _material.shader = playerShader;
- }
- }
- }
}
--
Gitblit v1.8.0