using System; using System.Collections; using System.Collections.Generic; using Thousandto.Core.Asset; using Thousandto.Core.Base; using UnityEngine; namespace Thousandto.Code.Center { public class SceneRestoreTexManger { #region//私有变量 private Dictionary _cacheTex = new Dictionary(); #endregion #region//静态实例 private static SceneRestoreTexManger _instance = null; public static SceneRestoreTexManger Instance { get { if (_instance == null) { _instance = new SceneRestoreTexManger(); } return _instance; } } #endregion public void SetTexture(string name, Action action) { Texture tex = _cacheTex.TryGetValue(name, out tex) ? tex : null; if (tex == null) { LoadTexture(name, action); } else { if (action != null) { action(tex); } } } public void ReleaseTexture(string path) { UnLoadTexture(path); } #region//私有函数 private void LoadTexture(string name, Action action) { string path = AssetUtils.GetImageAssetPath(ImageTypeCode.VFX, name); TextureManager.SharedInstance.LoadTexture(path, (info) => { if (info != null && info.AssetObject != null) { if (action != null) { action(info.AssetObject); } _cacheTex[path] = info.AssetObject; } }); } private void UnLoadTexture(string name) { string path = AssetUtils.GetImageAssetPath(ImageTypeCode.VFX, name); TextureManager.SharedInstance.UnLoadTexture(path, UnLoadFinish, true); } private void UnLoadFinish(TextureInfo info) { if (info != null) { if (_cacheTex.ContainsKey(info.AssetPath)) { _cacheTex.Remove(info.AssetPath); } } } #endregion } }