Browse Source

Merge branch 'master' of http://10.108.64.190:3000/gfg/client

huangxiaoyue 1 year ago
parent
commit
221fd0fb84

+ 13 - 5
GameClient/Assets/Editor/BuildEditor/PresetAssetHelper.cs

@@ -59,15 +59,23 @@ namespace GFGEditor
             {
                 if(dressUpCfg.loadType > 0)
                 {
-                    string assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 1);
+                    string assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 1);
                     TryAdd(assetPath, manifest, bundles); 
-                    assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 2);
+                    assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 2);
                     TryAdd(assetPath, manifest, bundles);
-                    assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 3);
+                    assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 3);
                     TryAdd(assetPath, manifest, bundles);
-                    assetPath = ResPathUtil.GetDressUpAnimationPath(dressUpCfg.res);
+                    assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 1);
                     TryAdd(assetPath, manifest, bundles);
-                    assetPath = ResPathUtil.GetDressUpEffectPath(dressUpCfg.res);
+                    assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 2);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 3);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 1);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 2);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 3);
                     TryAdd(assetPath, manifest, bundles);
                 }
             }

+ 74 - 2
GameClient/Assets/Game/HotUpdate/Assets/PreloadManager.cs

@@ -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();

+ 4 - 0
GameClient/Assets/Game/HotUpdate/Data/CardDataManager.cs

@@ -62,6 +62,10 @@ namespace GFGGame
             }
             _cardDicByType[0][cardData.id] = cardData;
             _cardDicByType[cardData.mainScore][cardData.id] = cardData;
+            if(GameGlobal.AfterDataInited)
+            {
+                PreloadManager.Instance.PreloadCardAnimationRes(cardData.id);
+            }
         }
 
         public static List<string> GetCardResources(ItemCfg itemCfg)

+ 1 - 0
GameClient/Assets/Game/HotUpdate/Data/DressUpMenuItemDataManager.cs

@@ -74,6 +74,7 @@ namespace GFGGame
                 {
                     AddNewDressItem(value);
                     DressUpMenuSuitDataManager.CheckItemInSuit(value);
+                    PreloadManager.Instance.PreloadDressUpRes(value);
                 }
                 else
                 {

+ 1 - 25
GameClient/Assets/Game/HotUpdate/DressUp/DressUpObj.cs

@@ -275,32 +275,8 @@ namespace GFGGame
             bool hasSuitActionRes = DressUpMenuSuitDataManager.CheckSuitHasActionRes(_dressUpData.suitId);
             _dressUpData.actionId = (hasSuitActionRes && tryShowAction) ? suitId : 0;
             
-            List<int> items = new List<int>(suitCfg.partsArr);
-            if (showOptional)
-            {
-                if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
-                {
-                    items.AddRange(suitCfg.partsOptionalArr);
-                }
-            }
-            int subType = 0;
             //找到要穿的散件
-            List<int> targetItemList = new List<int>();
-            foreach (int itemId in items)
-            {
-                if (!CheckOwn || DressUpMenuItemDataManager.CheckHasItem(itemId))
-                {
-                    subType = ItemUtilCS.GetItemSubType(itemId);
-                    bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
-                    if (!IsAction || notInAction)
-                    {
-                        if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
-                        {
-                            targetItemList.Add(itemId);
-                        }
-                    }
-                }
-            }
+            List<int> targetItemList = DressUpUtil.GetSuitItems(suitId, IsAction, excludeType, showOptional, CheckOwn);
             CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
             checkDefaultItem();
         }

+ 39 - 5
GameClient/Assets/Game/HotUpdate/DressUp/DressUpUtil.cs

@@ -4,6 +4,7 @@ using System.IO;
 using UnityEngine.Rendering;
 using YooAsset;
 using System.Collections.Generic;
+using System;
 
 namespace GFGGame
 {
@@ -228,13 +229,12 @@ namespace GFGGame
 
         private static DressUpLayerOperation UpdateLayerResAsync(ItemCfg itemCfg, GameObject parentObj, int layerId, bool needSetMask, bool showAni = true)
         {
-            string res = ResPathUtil.GetDressUpItemLayerRes(itemCfg, layerId);
             string resPath;
             string aniResPath = null;
             //根据资源存在与否再次检查是否播放动画
             if (showAni)
             {
-                aniResPath = ResPathUtil.GetDressUpAnimationPath(res);
+                aniResPath = ResPathUtil.GetDressUpLayerAnimationResPath(itemCfg, layerId);
                 if(!YooAssets.CheckResExist(aniResPath))
                 {
                     showAni = false;
@@ -247,7 +247,7 @@ namespace GFGGame
             }
             else
             {
-                resPath = ResPathUtil.GetDressUpPath(itemCfg, layerId);
+                resPath = ResPathUtil.GetDressUpLayerSpriteResPath(itemCfg, layerId);
             }
 
             if (!YooAssets.CheckResExist(resPath))
@@ -256,7 +256,7 @@ namespace GFGGame
             }
 
             //特效
-            string effectResPath = ResPathUtil.GetDressUpEffectPath(res, showAni);
+            string effectResPath = ResPathUtil.GetDressUpLayerEffectResPath(itemCfg, layerId);
             if (!YooAssets.CheckResExist(effectResPath))
             {
                 effectResPath = null;
@@ -499,7 +499,41 @@ namespace GFGGame
 
         }
 
-
+        public static List<int> GetSuitItems(int suitId, bool isAction, int[] excludeType = null, bool showOptional = true, bool CheckOwn = true)
+        {
+            SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
+            if (suitCfg == null)
+            {
+                return null;
+            }
+            List<int> items = new List<int>(suitCfg.partsArr);
+            if (showOptional)
+            {
+                if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
+                {
+                    items.AddRange(suitCfg.partsOptionalArr);
+                }
+            }
+            int subType = 0;
+            //找到要穿的散件
+            List<int> targetItemList = new List<int>();
+            foreach (int itemId in items)
+            {
+                if (!CheckOwn || DressUpMenuItemDataManager.CheckHasItem(itemId))
+                {
+                    subType = ItemUtilCS.GetItemSubType(itemId);
+                    bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
+                    if (!isAction || notInAction)
+                    {
+                        if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
+                        {
+                            targetItemList.Add(itemId);
+                        }
+                    }
+                }
+            }
+            return targetItemList;
+        }
     }
 
 }

+ 13 - 3
GameClient/Assets/Game/HotUpdate/Utils/ResPathUtil.cs

@@ -67,9 +67,9 @@ namespace GFGGame
         {
             return $"{TEXTURE_SCENEBG_DIR_PATH}/{res}.{extName}";
         }
-        public static string GetDressUpPath(ItemCfg itemCfg, int layerId)
+        public static string GetDressUpLayerSpriteResPath(ItemCfg itemCfg, int layerId)
 {
-            string res = GetDressUpItemLayerRes(itemCfg, layerId);
+            string res = GetDressUpLayerResName(itemCfg, layerId);
             if(itemCfg.subType == ConstDressUpItemType.BEI_JING)
             {
                 return GetSceneBgPath(res);
@@ -142,6 +142,11 @@ namespace GFGGame
             return $"{ANIMATION_DIR_PATH}/DressUp/{res}";
         }
 
+        public static string GetDressUpLayerAnimationResPath(ItemCfg itemCfg, int layerId)
+        {
+            string res = GetDressUpLayerResName(itemCfg, layerId);
+            return GetDressUpAnimationPath(res);
+        }
         public static string GetDressUpAnimationPath(string res, string extName = "prefab")
         {
             return $"{GetDressUpAnimationDirPath(res)}/{res}.{extName}";
@@ -157,6 +162,11 @@ namespace GFGGame
             return YooAssets.CheckResExist(resPath);
         }
 
+        public static string GetDressUpLayerEffectResPath(ItemCfg itemCfg, int layerId)
+        {
+            string res = GetDressUpLayerResName(itemCfg, layerId);
+            return GetDressUpEffectPath(res);
+        }
         public static string GetDressUpEffectDirPath(string res)
         {
             return $"{EFFECT_DIR_PATH}/DressUp/{res}";
@@ -217,7 +227,7 @@ namespace GFGGame
             return $"{TEXTURE_DIR_PATH}/LeagueIcon/{res}.{extName}";
         }
 
-        public static string GetDressUpItemLayerRes(ItemCfg itemCfg, int layerId)
+        public static string GetDressUpLayerResName(ItemCfg itemCfg, int layerId)
         {
             string res = itemCfg.res;
             switch (layerId)