123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using GFGGame.Launcher;
- using System.Collections.Generic;
- using YooAsset;
- namespace GFGGame
- {
- public enum ResType
- {
- Sprite,
- Animation,
- Both
- }
- //负责提供获得卡牌和衣服部件时开启后台预下载的接口
- public class PreDownloadManager : SingletonMonoBase<PreDownloadManager>
- {
- private List<string> waitList = new List<string>();
- private ResourceDownloaderOperation downloaderOperation;
- private string[] locationsLoading;
- public void TryAdd(string location)
- {
- if (LoadManager.Instance.CheckResExsited(location)) return;
- if (!YooAssets.CheckResExist(location)) return;
- waitList.Add(location);
- LogUtil.LogEditor($"PreloadManager TryAdd {location}");
- }
- /// <summary>
- /// 预加载套装资源
- /// </summary>
- /// <param name="suitId"></param>
- /// <param name="resType">可以选择预加载静态图或者动画或者全部</param>
- /// <param name="excludeType">排除一些类型,由ConstDressUpItemType定义</param>
- /// <param name="includeOptional">是否包含可选部件</param>
- public void PreDownloadSuitRes(int suitId, ResType resType, int[] excludeType, bool includeOptional)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
- if (suitCfg == null)
- {
- return;
- }
- //找到要穿的散件
- List<int> targetItemList = DressUpUtil.GetSuitItems(suitId, resType != ResType.Sprite, excludeType, includeOptional, false);
- foreach (var itemId in targetItemList)
- {
- PreDownloadDressUpRes(itemId, resType);
- }
- if (resType != ResType.Sprite)
- {
- if (!string.IsNullOrEmpty(suitCfg.aniRes))
- {
- string assetPath = ResPathUtil.GetDressUpAnimationPath(suitCfg.aniRes);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpEffectPath(suitCfg.aniRes, true);
- PreDownloadManager.Instance.TryAdd(assetPath);
- }
- }
- }
- public void PreDownloadDressUpRes(int itemId, ResType resType = ResType.Sprite)
- {
- ItemCfg dressUpCfg = ItemCfgArray.Instance.GetCfg(itemId);
- string assetPath;
- if (resType != ResType.Animation)
- {
- assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 1);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 2);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 3);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 1, false);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 2, false);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 3, false);
- PreDownloadManager.Instance.TryAdd(assetPath);
- }
- if (resType != ResType.Sprite)
- {
- assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 1);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 2);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 3);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 1, true);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 2, true);
- PreDownloadManager.Instance.TryAdd(assetPath);
- assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 3, true);
- PreDownloadManager.Instance.TryAdd(assetPath);
- }
- }
- public void PreDownloadCardAnimationRes(int itemId)
- {
- ItemCfg cardCfg = ItemCfgArray.Instance.GetCfg(itemId);
- string assetPath = ResPathUtil.GetCardAnimationPath(cardCfg.res);
- PreDownloadManager.Instance.TryAdd(assetPath);
- }
- private void Update()
- {
- if(downloaderOperation != null)
- {
- if(downloaderOperation.IsDone)
- {
- foreach(var t in locationsLoading)
- {
- LoadManager.Instance.SetResDownloaded(t);
- }
- downloaderOperation = null;
- locationsLoading = null;
- }
- }
- if(downloaderOperation == null && waitList.Count > 0)
- {
- waitList.Reverse();//看了yooasset源码,疑似他是从后往前加载,这里翻转一下
- locationsLoading = waitList.ToArray();
- downloaderOperation = YooAssets.CreateBundleDownloader(locationsLoading, 1, 3);
- downloaderOperation.BeginDownload();
- waitList.Clear();
- }
- }
- }
- }
|