|
@@ -4,15 +4,87 @@ using YooAsset;
|
|
|
|
|
|
namespace GFGGame
|
|
|
{
|
|
|
+ public enum ResType
|
|
|
+ {
|
|
|
+ Sprite,
|
|
|
+ Animation,
|
|
|
+ Both
|
|
|
+ }
|
|
|
+
|
|
|
public class PreloadManager : SingletonMonoBase<PreloadManager>
|
|
|
{
|
|
|
private List<string> waitList = new List<string>();
|
|
|
private ResourceDownloaderOperation downloaderOperation;
|
|
|
private string[] locationsLoading;
|
|
|
|
|
|
- public void Add(string location)
|
|
|
+ public void TryAdd(string location)
|
|
|
{
|
|
|
+ if (LoadManager.Instance.CheckResExsited(location)) return;
|
|
|
+ if (!YooAssets.CheckResExist(location)) return;
|
|
|
waitList.Add(location);
|
|
|
+ LogUtil.LogEditor($"PreloadManager TryAdd {location}");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void AddSuit(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)
|
|
|
+ {
|
|
|
+ PreloadDressUpRes(itemId, resType);
|
|
|
+ }
|
|
|
+ if (resType != ResType.Sprite)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(suitCfg.aniRes))
|
|
|
+ {
|
|
|
+ string assetPath = ResPathUtil.GetDressUpAnimationPath(suitCfg.aniRes);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpEffectPath(suitCfg.aniRes);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PreloadDressUpRes(int itemId, ResType resType = ResType.Sprite)
|
|
|
+ {
|
|
|
+ ItemCfg dressUpCfg = ItemCfgArray.Instance.GetCfg(itemId);
|
|
|
+ string assetPath;
|
|
|
+ if (resType != ResType.Animation)
|
|
|
+ {
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 1);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 2);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 3);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ }
|
|
|
+ if (resType != ResType.Sprite)
|
|
|
+ {
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 1);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 2);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 3);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 1);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 2);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 3);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PreloadCardAnimationRes(int itemId)
|
|
|
+ {
|
|
|
+ ItemCfg cardCfg = ItemCfgArray.Instance.GetCfg(itemId);
|
|
|
+ string assetPath = ResPathUtil.GetCardAnimationPath(cardCfg.res);
|
|
|
+ PreloadManager.Instance.TryAdd(assetPath);
|
|
|
}
|
|
|
|
|
|
private void Update()
|
|
@@ -30,7 +102,7 @@ namespace GFGGame
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(downloaderOperation == null)
|
|
|
+ if(downloaderOperation == null && waitList.Count > 0)
|
|
|
{
|
|
|
waitList.Reverse();//看了yooasset源码,疑似他是从后往前加载,这里翻转一下
|
|
|
locationsLoading = waitList.ToArray();
|