| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
|   | 
| /// <summary> | 
| /// UI帧动画管理器 - 负责帧动画资源的加载和管理 | 
| /// </summary> | 
| public class UIFrameMgr { | 
|     private static UIFrameMgr _inst = null; | 
|     private static readonly object _lock = new object(); | 
|      | 
|     public static UIFrameMgr Inst { | 
|         get { | 
|             if (_inst == null) { | 
|                 lock (_lock) { | 
|                     if (_inst == null) { | 
|                         _inst = new UIFrameMgr(); | 
|                     } | 
|                 } | 
|             } | 
|             return _inst; | 
|         } | 
|     } | 
|   | 
|     // 帧动画资源缓存 | 
|     private Dictionary<string, List<Sprite>> allFrameDic = new Dictionary<string, List<Sprite>>(); | 
|     // 是否已初始化 | 
|     private bool isInitialized = false; | 
|   | 
|     public UIFrameMgr() | 
|     { | 
|         Init(); | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 初始化管理器 | 
|     /// </summary> | 
|     public void Init() | 
|     { | 
|         if (isInitialized) | 
|             return; | 
|              | 
|         allFrameDic.Clear(); | 
|         isInitialized = true; | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 加载指定帧动画资源 | 
|     /// </summary> | 
|     private void LoadFrameSprites(FrameAnimationConfig cfg) | 
|     { | 
|         if (allFrameDic.ContainsKey(cfg.name)) | 
|             return; | 
|              | 
|         List<Sprite> spriteList = new List<Sprite>(); | 
|          | 
|         for (int i = 1; i <= cfg.frameCnt; i++) | 
|         { | 
|             string spritePath = "Sprite/" + cfg.folder; | 
|             string spriteName = StringUtility.Contact(cfg.name, "_", i); | 
|              | 
|             Sprite sprite = ResManager.Instance.LoadAsset<Sprite>(spritePath, spriteName); | 
|             if (sprite != null) | 
|             { | 
|                 spriteList.Add(sprite); | 
|             } | 
|         } | 
|          | 
|         if (spriteList.Count > 0) | 
|         { | 
|             allFrameDic.Add(cfg.name, spriteList); | 
|         } | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 获取帧动画资源 | 
|     /// </summary> | 
|     public List<Sprite> GetDynamicImage(string key) | 
|     { | 
|         // 按需加载资源 | 
|         if (!allFrameDic.ContainsKey(key)) | 
|         { | 
|             LoadFrameSprites(FrameAnimationConfig.Get(key)); | 
|         } | 
|          | 
|         if (allFrameDic.TryGetValue(key, out var list)) | 
|         { | 
|             return list; | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 检查是否包含指定帧动画 | 
|     /// </summary> | 
|     public bool ContainsDynamicImage(string key) | 
|     { | 
|         return FrameAnimationConfig.HasKey(key); | 
|     } | 
|      | 
|      | 
|     /// <summary> | 
|     /// 预加载指定帧动画 | 
|     /// </summary> | 
|     public void PreloadDynamicImage(string key) | 
|     { | 
|         if (!allFrameDic.ContainsKey(key)) | 
|         { | 
|             LoadFrameSprites(FrameAnimationConfig.Get(key)); | 
|         } | 
|     } | 
| } |