guodong před 2 roky
rodič
revize
a1c10baae1

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Data/DressUpMenuSuitDataManager.cs

@@ -232,7 +232,7 @@ namespace GFGGame
         public static bool CheckSuitHasActionRes(int suitId)
         {
             var suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
-            return suitCfg != null && ResPathUtil.CheckDressUpAnimationExist(suitCfg.aniRes);
+            return suitCfg != null && ResPathUtil.CheckDressUpAnimationResExist(suitCfg.aniRes);
         }
 
     }

+ 15 - 12
GameClient/Assets/Game/HotUpdate/DressUp/DressUpObj.cs

@@ -238,7 +238,6 @@ namespace GFGGame
             if (checkDefault)
             {
                 checkDefaultItem();
-                UpdateWholeBodyView();
             }
             RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
             // FightDataManager.Instance.score = roleLevelCfg.baseScore;
@@ -326,7 +325,6 @@ namespace GFGGame
                 }
             }
             checkDefaultItem();
-            UpdateWholeBodyView();
         }
 
         //穿上一个动作
@@ -350,7 +348,6 @@ namespace GFGGame
                 CancelAction(true);
             }
             checkDefaultItem();
-            UpdateWholeBodyView();
         }
 
         //取消动作
@@ -400,7 +397,6 @@ namespace GFGGame
                 AddOrRemove(itemID, false, true);
             }
             checkDefaultItem();
-            UpdateWholeBodyView();
 
         }
 
@@ -419,7 +415,6 @@ namespace GFGGame
                 AddOrRemove(itemID, false, true);
             }
             checkDefaultItem();
-            UpdateWholeBodyView();
         }
 
         public int GetItemIdBuyType(int subType)
@@ -516,6 +511,8 @@ namespace GFGGame
             bool hasNeiDaDefault = false;
             //是否有默认下装
             bool hasXiaZhuangDefault = false;
+            //是否有妆容
+            bool hasZhuangRong = false;
             for (int i = 0; i < _dressUpData.itemList.Count; i++)
             {
                 int itemID = (int)_dressUpData.itemList[i];
@@ -540,6 +537,11 @@ namespace GFGGame
                 {
                     hasShangYi = true;
                 }
+                else if (subType == ConstDressUpItemType.ZHUANG_RONG)
+                {
+                    hasZhuangRong = true;
+                }
+
                 if (itemID == ConstItemID.DEFULT_NEI_DA)
                 {
                     hasNeiDaDefault = true;
@@ -577,23 +579,24 @@ namespace GFGGame
 
                 }
             }
-
             CheckCurDressIsSuit();
+            DressUpUtil.UpdateHead(!hasZhuangRong, _sceneObj, _needSetMask, _roleObj);
+            UpdateBodyView();
         }
 
-        //更新整个身体层(包括头和躯干)
-        private void UpdateWholeBodyView()
+        //更新整个身体
+        private void UpdateBodyView()
         {
             if (IsAction)
             {
                 SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_dressUpData.actionId);
-                var hasAniRes = ResPathUtil.CheckDressUpAnimationExist(suitCfg.aniRes);
-                var res = hasAniRes ? suitCfg.aniRes : null;
-                DressUpUtil.UpdateWholeBody(res, _sceneObj, hasAniRes, res, false, _roleObj);
+                var hasAniRes = ResPathUtil.CheckDressUpAnimationResExist(suitCfg.aniRes);
+                var actionRes = hasAniRes ? suitCfg.aniRes : null;
+                DressUpUtil.UpdateBody(actionRes, _sceneObj, _needSetMask, _roleObj);
             }
             else
             {
-                DressUpUtil.UpdateWholeBody(null, _sceneObj, false, null, _needSetMask, _roleObj);
+                DressUpUtil.UpdateBody(null, _sceneObj, _needSetMask, _roleObj);
             }
         }
 

+ 76 - 52
GameClient/Assets/Game/HotUpdate/DressUp/DressUpUtil.cs

@@ -137,57 +137,73 @@ namespace GFGGame
             }
         }
 
-        public static void InitHead(GameObject sceneObj, bool needSetMask = false, GameObject parentObj = null)
+        public static void UpdateHead(bool show, GameObject sceneObj, bool needSetMask = false, GameObject parentObj = null)
         {
             var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
             parentObj = parentObj == null ? roleTf.gameObject : parentObj;
             string res = HEAD_DEFAULT_RES_NAME;
+
             Transform transform_t = parentObj.transform.Find(HEAD_SPRITE_NAME);
-            if (transform_t != null)
+            if (show)
             {
-                return;
+                if (transform_t != null)
+                {
+                    transform_t.gameObject.SetActive(true);
+                    return;
+                }
+                AddSpriteObj(res, "png", HEAD_SPRITE_NAME, parentObj, 1, needSetMask);
+            }
+            else
+            {
+                if(transform_t == null)
+                {
+                    return;
+                }
+                transform_t.gameObject.SetActive(false);
             }
-            AddSpriteObj(res, "png", HEAD_SPRITE_NAME, parentObj, 1, needSetMask);
-        }
-
-        public static void UpdateWholeBody(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
-        {
-            InitHead(sceneObj, needSetMask, parentObj);
-            UpdateBodyOnly(res, sceneObj, isAni, effRes, needSetMask, parentObj);
         }
 
-        public static void UpdateBodyOnly(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
+        public static void UpdateBody(string actionRes, GameObject sceneObj, bool needSetMask = false, GameObject parentObj = null)
         {
             //角色
             var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
             parentObj = parentObj == null ? roleTf.gameObject : parentObj;
-            if (res == null)
+
+            var extPng = "png";
+            if (!string.IsNullOrEmpty(actionRes))
+            {
+                string resPath = ResPathUtil.GetDressUpAnimationPath(actionRes);
+                if (CheckGameObjExisted(parentObj, BODY_ANIMATION_NAME, resPath))
+                {
+                    return;
+                }
+            }
+            else
             {
-                res = BODY_DEFAULT_RES_NAME;
+                string resPath = ResPathUtil.GetDressUpPath(BODY_DEFAULT_RES_NAME, extPng);
+                if (CheckGameObjExisted(parentObj, BODY_SPRITE_NAME, resPath))
+                {
+                    return;
+                }
             }
 
-            //清理旧的
-            TryRemoveObj(parentObj, BODY_SPRITE_NAME);
             var removeBodyAni = TryRemoveObj(parentObj, BODY_ANIMATION_NAME);
             TryRemoveObj(parentObj, BODY_EFFECT_OBJ_NAME);
-
-            if (isAni)
+            TryRemoveObj(parentObj, BODY_SPRITE_NAME);
+            if (!string.IsNullOrEmpty(actionRes))
             {
-                AddAnimationObj(res, BODY_ANIMATION_NAME, parentObj, 0);
+                AddAnimationObj(actionRes, BODY_ANIMATION_NAME, parentObj, 0);
+                //特效
+                TryAddEffectObj(actionRes, BODY_EFFECT_OBJ_NAME, parentObj, 0, false);
             }
             else
             {
-                AddSpriteObj(res, "png", BODY_SPRITE_NAME, parentObj, 0, needSetMask);
+                AddSpriteObj(BODY_DEFAULT_RES_NAME, extPng, BODY_SPRITE_NAME, parentObj, 0, needSetMask);
                 if (removeBodyAni)
                 {
                     parentObj.transform.SetPositionAndRotation(new Vector3(), new Quaternion());
                 }
             }
-            //特效
-            if (!string.IsNullOrEmpty(effRes))
-            {
-                TryAddEffectObj(effRes, BODY_EFFECT_OBJ_NAME, parentObj, 0, false);
-            }
         }
 
         public static void AddAssetReleaser(GameObject gameObj, string resPath)
@@ -243,17 +259,17 @@ namespace GFGGame
             //清理旧的
             var spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, layerId);
             TryRemoveObj(parentObj, spritObjName);
-            var aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
-            TryRemoveObj(parentObj, aniObjName);
+            var objName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
+            TryRemoveObj(parentObj, objName);
             string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
             //这里需要先添加静态图,防止加载动画有延迟,出现光头
             GameObject spriteObj = AddSpriteObj(res, ext, spritObjName, parentObj, sortingOrder, needSetMask);
 
-            GameObject aniObj = null;
+            GameObject addAniObj = null;
             if (showAni)
             {
-                aniObj = AddAnimationObj(res, aniObjName, parentObj, sortingOrder);
-                if (aniObj != null && spriteObj != null)
+                addAniObj = AddAnimationObj(res, objName, parentObj, sortingOrder);
+                if (addAniObj != null && spriteObj != null)
                 {
                     Timers.inst.Add(0.03f, 1, (obj) =>
                     {
@@ -280,9 +296,9 @@ namespace GFGGame
                 }
             }
 
-            aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, layerId);
-            TryRemoveObj(parentObj, aniObjName);
-            TryAddEffectObj(res, aniObjName, parentObj, sortingOrder, aniObj != null);
+            objName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, layerId);
+            TryRemoveObj(parentObj, objName);
+            TryAddEffectObj(res, objName, parentObj, sortingOrder, addAniObj != null);
         }
 
         private static GameObject AddSpriteObj(string res, string ext, string objName, GameObject parentObj, int sortingOrder, bool needSetMask)
@@ -292,6 +308,10 @@ namespace GFGGame
             {
                 return null;
             }
+            if (CheckGameObjExisted(parentObj, objName, resPath))
+            {
+                return null;
+            }
             SpriteRenderer spr = null;
             var gameObj = parentObj.transform.Find(objName)?.gameObject;
             if (gameObj == null)
@@ -370,6 +390,30 @@ namespace GFGGame
             return gameObj;
         }
 
+        private static void TryAddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder, bool inAniDir)
+        {
+            var resPath = ResPathUtil.GetDressUpEffectPath(res, inAniDir);
+            if (!VEngine.Versions.Contains(resPath))
+            {
+                return;
+            }
+            if (CheckGameObjExisted(parentObj, objName, resPath))
+            {
+                return;
+            }
+            GameObject effPre = GFGAsset.Load<GameObject>(resPath);
+            var gameObj = GameObject.Instantiate(effPre);
+            AddAssetReleaser(gameObj, resPath);
+            gameObj.transform.SetParent(parentObj.transform, false);
+            gameObj.name = objName;
+            var sortingGroup = gameObj.transform.GetComponent<SortingGroup>();
+            if (sortingGroup != null)
+            {
+                GameObject.Destroy(sortingGroup);
+            }
+            SetRenderersOrder(gameObj, sortingOrder + 1);//特效层默认高一个层级
+        }
+
         private static bool TryRemoveObj(GameObject parentObj, string objName)
         {
             if (parentObj == null)
@@ -428,26 +472,6 @@ namespace GFGGame
             return gameObj;
         }
 
-        private static void TryAddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder, bool inAni)
-        {
-            var resPath = ResPathUtil.GetDressUpEffectPath(res, inAni);
-            if (!VEngine.Versions.Contains(resPath))
-            {
-                return;
-            }
-            GameObject effPre = GFGAsset.Load<GameObject>(resPath);
-            var gameObj = GameObject.Instantiate(effPre);
-            AddAssetReleaser(gameObj, resPath);
-            gameObj.transform.SetParent(parentObj.transform, false);
-            gameObj.name = objName;
-            var sortingGroup = gameObj.transform.GetComponent<SortingGroup>();
-            if (sortingGroup != null)
-            {
-                GameObject.Destroy(sortingGroup);
-            }
-            SetRenderersOrder(gameObj, sortingOrder + 1);//特效层默认高一个层级
-        }
-
         public static void LoadSpritePos(string res, out float tx, out float ty)
         {
             string resPath = ResPathUtil.GetDressUpPath(res, "bytes");

+ 1 - 1
GameClient/Assets/Game/HotUpdate/DressUp/SceneController.cs

@@ -16,7 +16,7 @@ namespace GFGGame
             DressUpUtil.AddAssetReleaser(tf.gameObject, resPath);
             spr.sprite = sp;
             //角色
-            DressUpUtil.UpdateBodyOnly("ui_loginrole", sceneObj, true);
+            DressUpUtil.UpdateBody("ui_loginrole", sceneObj);
         }
 
         public static void UpdateMainScene(GameObject sceneObj)

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

@@ -116,7 +116,7 @@ namespace GFGGame
             return $"{GetDressUpAnimationDirPath(res)}/{res}.{extName}";
         }
 
-        public static bool CheckDressUpAnimationExist(string res, string extName = "prefab")
+        public static bool CheckDressUpAnimationResExist(string res, string extName = "prefab")
         {
             if(string.IsNullOrEmpty(res))
             {
@@ -135,9 +135,9 @@ namespace GFGGame
             return $"{EFFECT_DIR_PATH}/DressUp/{res}";
         }
 
-        public static string GetDressUpEffectPath(string res, bool inAni = false, string extName = "prefab")
+        public static string GetDressUpEffectPath(string res, bool inAniDir = false, string extName = "prefab")
         {
-            return $"{GetDressUpEffectDirPath(res, inAni)}/{res}.{extName}";
+            return $"{GetDressUpEffectDirPath(res, inAniDir)}/{res}.{extName}";
         }
         public static string GetViewEffectPath(string uiName, string resName, string extName = "prefab")
         {