浏览代码

Merge branch 'master' of http://git.gfggame.com:3000/gfg/client

zhaoyang 3 年之前
父节点
当前提交
62269534b2

+ 110 - 55
GameClient/Assets/Game/HotUpdate/DressUp/DressUpUtil.cs

@@ -9,9 +9,11 @@ namespace GFGGame
     {
         private const string BODY_DEFAULT_RES_NAME = "renmo";
         private const string ROLE_OBJ_NAME = "Role";
-        private const string BODY_OBJ_NAME = "Body";
+        private const string BODY_SPRITE_NAME = "Body";
+        private const string BODY_ANIMATION_NAME = "Body_a";
         private const string BODY_EFFECT_OBJ_NAME = "Body_eff";
-        private const string FORMAT_OBJ_NAME = "T{0}_{1}";
+        private const string FORMAT_SPRITE_NAME = "T{0}_s{1}";
+        private const string FORMAT_ANIMATION_NAME = "T{0}_a{1}";
         private const string FORMAT_EFFECT_OBJ_NAME = "T{0}_eff";
         private const string FORMAT_LAYER_RES_NAME_WITH_T = "{0}_t";
 
@@ -84,34 +86,23 @@ namespace GFGGame
                     Transform role = sceneObj.transform.Find(ROLE_OBJ_NAME);
                     parentObj = role.gameObject;
                 }
-                string objName;
+                string spritObjName;
+                string aniObjName;
                 //默认层
                 if (itemCfg.resLayer1 > 0)
                 {
-                    objName = string.Format(FORMAT_OBJ_NAME, itemCfg.subType, 1);
-                    Transform transform = parentObj.transform.Find(objName);
-                    if (transform != null)
-                    {
-                        GameObject gameObj = transform.gameObject;
-                        if (gameObj != null)
-                        {
-                            GameObject.DestroyImmediate(gameObj);
-                        }
-                    }
+                    spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 1);
+                    TryClearSpriteObj(parentObj, spritObjName);
+                    aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 1);
+                    TryRemoveAnimationObj(parentObj, aniObjName);
                 }
                 //特殊层
                 if (itemCfg.resLayer2 > 0)
                 {
-                    objName = string.Format(FORMAT_OBJ_NAME, itemCfg.subType, 2);
-                    Transform transform_t = parentObj.transform.Find(objName);
-                    if (transform_t != null)
-                    {
-                        GameObject gameObj_t = transform_t.gameObject;
-                        if (gameObj_t != null)
-                        {
-                            GameObject.DestroyImmediate(gameObj_t);
-                        }
-                    }
+                    spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 2);
+                    TryClearSpriteObj(parentObj, spritObjName);
+                    aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 2);
+                    TryRemoveAnimationObj(parentObj, aniObjName);
                 }
 
                 //特效
@@ -130,37 +121,34 @@ namespace GFGGame
         public static void UpdateBody(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
         {
             //角色
-            Transform roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
-            GameObject roleObj = parentObj == null ? roleTf.gameObject : parentObj;
+            var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
+            parentObj = parentObj == null ? roleTf.gameObject : parentObj;
             if (res == null)
             {
                 res = BODY_DEFAULT_RES_NAME;
             }
-            var objName = BODY_OBJ_NAME;
-            Transform tf = roleObj.transform.Find(objName);
-            if (tf != null)
-            {
-                GameObject.DestroyImmediate(tf.gameObject);
-                tf = null;
-            }
+
+            //清理旧的
+            TryClearSpriteObj(parentObj, BODY_SPRITE_NAME);
+            TryRemoveAnimationObj(parentObj, BODY_ANIMATION_NAME);
+
             if (isAni)
             {
-                AddAnimationObj(res, objName, roleObj, 0);
+                AddAnimationObj(res, BODY_ANIMATION_NAME, parentObj, 0);
             }
             else
             {
-                AddSpriteObj(res, "png", objName, roleObj, 0, needSetMask);
+                AddSpriteObj(res, "png", BODY_SPRITE_NAME, parentObj, 0, needSetMask);
             }
             //特效
-            objName = BODY_EFFECT_OBJ_NAME;
-            tf = roleObj.transform.Find(objName);
+            var tf = parentObj.transform.Find(BODY_EFFECT_OBJ_NAME);
             if (tf != null)
             {
                 GameObject.DestroyImmediate(tf.gameObject);
             }
             if (!string.IsNullOrEmpty(effRes))
             {
-                AddEffectObj(effRes, objName, roleObj, 0);
+                AddEffectObj(effRes, BODY_EFFECT_OBJ_NAME, parentObj, 0);
             }
         }
 
@@ -184,7 +172,7 @@ namespace GFGGame
         {
 
             ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
-            string objName = string.Format(FORMAT_OBJ_NAME, typeCfg.type, layerId);
+            //string objName = string.Format(FORMAT_SPRITE_NAME, typeCfg.type, layerId);
             string res = itemCfg.res;
             int sortingOrder = typeCfg.defaultLayer;
             if (layerId == 2)
@@ -195,24 +183,33 @@ namespace GFGGame
             {
                 res = string.Format(FORMAT_LAYER_RES_NAME_WITH_T, res);
             }
-            Transform tf = parentObj.transform.Find(objName);
-            if (tf != null)
-            {
-                GameObject.DestroyImmediate(tf.gameObject);
-                tf = null;
-            }
+            //清理旧的
+            var spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, layerId);
+            TryClearSpriteObj(parentObj, spritObjName);
+            var aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
+            TryRemoveAnimationObj(parentObj, aniObjName);
             string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
-            AddSpriteObj(res, ext, objName, parentObj, sortingOrder, needSetMask);
+            AddSpriteObj(res, ext, spritObjName, parentObj, sortingOrder, needSetMask);
             if (itemCfg.isAni > 0 && showAni)
             {
-                tf = parentObj.transform.Find(objName);
-                AddAnimationObj(res, objName, parentObj, sortingOrder);
+                AddAnimationObj(res, aniObjName, parentObj, sortingOrder);
                 Timers.inst.Add(0.03f, 1, (obj) =>
                 {
+                    Transform tf = parentObj.transform.Find(spritObjName);
                     if (tf != null && tf.gameObject != null && tf.gameObject.activeInHierarchy)
                     {
-                        GameObject.DestroyImmediate(tf.gameObject);
-                        tf = null;
+                        var assetDisposer = tf.gameObject.GetComponent<AssetReleaser>();
+                        if (assetDisposer != null)
+                        {
+                            if (!string.IsNullOrEmpty(assetDisposer.resPath))
+                            {
+                                string resPath = ResPathUtil.GetDressUpPath(res, ext);
+                                if (assetDisposer.resPath == resPath)
+                                {
+                                    TryClearSpriteObj(parentObj, spritObjName);
+                                }
+                            }
+                        }
                     }
                 });
             }
@@ -223,10 +220,18 @@ namespace GFGGame
         {
             string resPath = ResPathUtil.GetDressUpPath(res, ext);
             SpriteRenderer spr = null;
-            var gameObj = new GameObject(objName);
-            spr = gameObj.AddComponent<SpriteRenderer>();
-            AddAssetReleaser(gameObj, resPath);
-            gameObj.transform.SetParent(parentObj.transform, false);
+            var gameObj = parentObj.transform.Find(objName)?.gameObject;
+            if(gameObj == null)
+            {
+                gameObj = new GameObject(objName);
+                gameObj.transform.SetParent(parentObj.transform, false);
+                AddAssetReleaser(gameObj, resPath);
+            }
+            spr = gameObj.GetComponent<SpriteRenderer>();
+            if(spr == null)
+            {
+                spr = gameObj.AddComponent<SpriteRenderer>();
+            }
             float tx, ty;
             LoadSpritePos(res, out tx, out ty);
             gameObj.transform.localPosition = new Vector3(tx, ty, gameObj.transform.localPosition.z);
@@ -245,6 +250,37 @@ namespace GFGGame
             return gameObj;
         }
 
+        private static void TryClearSpriteObj(GameObject parentObj, string spritObjName)
+        {
+            if(parentObj == null)
+            {
+                return;
+            }
+            Transform transform_t = parentObj.transform.Find(spritObjName);
+            if (transform_t != null)
+            {
+                GameObject gameObj_t = transform_t.gameObject;
+                if (gameObj_t != null)
+                {
+                    SpriteRenderer spr = null;
+                    spr = gameObj_t.GetComponent<SpriteRenderer>();
+                    if(spr != null)
+                    {
+                        spr.sprite = null;
+                    }
+                    var assetDisposer = gameObj_t.GetComponent<AssetReleaser>();
+                    if(assetDisposer != null)
+                    {
+                        if (!string.IsNullOrEmpty(assetDisposer.resPath))
+                        {
+                            GFGAsset.Release(assetDisposer.resPath);
+                            assetDisposer.resPath = null;
+                        }
+                    }
+                }
+            }
+        }
+
         private static GameObject AddAnimationObj(string res, string objName, GameObject parentObj, int sortingOrder)
         {
             string resPath = ResPathUtil.GetDressUpAnimationPath(res);
@@ -269,7 +305,25 @@ namespace GFGGame
             SetParticleSortingOrder(gameObj, sortingOrder);
             return gameObj;
         }
-        public static GameObject AddAnimationObj(string resPath)
+
+        private static void TryRemoveAnimationObj(GameObject parentObj, string aniObjName)
+        {
+            if (parentObj == null)
+            {
+                return;
+            }
+            Transform transform = parentObj.transform.Find(aniObjName);
+            if (transform != null)
+            {
+                GameObject gameObj = transform.gameObject;
+                if (gameObj != null)
+                {
+                    GameObject.DestroyImmediate(gameObj);
+                }
+            }
+        }
+
+        public static GameObject CreateAnimationObj(string resPath)
         {
             // string resPath = ResPathUtil.GetCardAnimationPath(res);
             var prefab = GFGAsset.Load<GameObject>(resPath);
@@ -281,6 +335,7 @@ namespace GFGGame
             AddAssetReleaser(gameObj, resPath);
             return gameObj;
         }
+
         private static GameObject AddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder)
         {
             var resPath = ResPathUtil.GetDressUpEffectPath(res);
@@ -293,7 +348,7 @@ namespace GFGGame
             return gameObj;
         }
 
-        public static void LoadSpritePos(string res, out float tx, out float ty)
+        private static void LoadSpritePos(string res, out float tx, out float ty)
         {
             string resPath = ResPathUtil.GetDressUpPath(res, "bytes");
             if (VEngine.Versions.Contains(resPath))

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

@@ -366,7 +366,7 @@ namespace GFGGame
                 GameObject.Destroy(_gameObject);
                 _gameObject = null;
             }
-            _gameObject = DressUpUtil.AddAnimationObj(res);
+            _gameObject = DressUpUtil.CreateAnimationObj(res);
             _gameObject.transform.localScale = new Vector3(scale, scale, scale);
 
             if (_wrapper == null)

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Views/Card/CardFosterView.cs

@@ -168,7 +168,7 @@ namespace GFGGame
             string resPath = ResPathUtil.GetCardAnimationPath(_cardData.resources[_cardData.resIndex]);
             if (Versions.Contains(resPath))
             {
-                _cardObj = DressUpUtil.AddAnimationObj(resPath);
+                _cardObj = DressUpUtil.CreateAnimationObj(resPath);
                 SceneController.AddObjectToView(_cardObj, _wrapper, _ui.m_comCard.m_comCardHolder.m_holder, resPath, out _cardObj, out _wrapper);
 
             }

二进制
GameClient/Assets/ResIn/Config/excelConfig.sqlite.bytes