Browse Source

增加拍照功能中添加物品时的判空

leiyasi 1 year ago
parent
commit
c436789ebc
1 changed files with 16 additions and 6 deletions
  1. 16 6
      GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographView.cs

+ 16 - 6
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographView.cs

@@ -236,8 +236,11 @@ namespace GFGGame
                 PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, 3, setLayer);
                 if (setLayer)
                 {
-                    parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
-                    pos = parentGameObj3.transform.localPosition;
+                    if(parentGameObj3.transform.childCount > 0)
+                    {
+                        parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
+                        pos = parentGameObj3.transform.localPosition;
+                    }
                 }
             }
             if (!string.IsNullOrEmpty(itemCfg.resLayer2))
@@ -246,8 +249,11 @@ namespace GFGGame
                 PhotographSceneManager.Instance.AddSceneItem(parentGameObj2, itemCfg, 2, setLayer);
                 if (setLayer)
                 {
-                    parentGameObj2.transform.localPosition = pos == Vector3.zero ? -parentGameObj2.transform.GetChild(0).localPosition : pos;
-                    pos = parentGameObj2.transform.localPosition;
+                    if (parentGameObj2.transform.childCount > 0)
+                    {
+                        parentGameObj2.transform.localPosition = pos == Vector3.zero ? -parentGameObj2.transform.GetChild(0).localPosition : pos;
+                        pos = parentGameObj2.transform.localPosition;
+                    }
                 }
             }
             if (!string.IsNullOrEmpty(itemCfg.resLayer1))
@@ -258,8 +264,12 @@ namespace GFGGame
 
                 if (setLayer)
                 {
-                    parentGameObj1.transform.localPosition = pos == Vector3.zero ? -parentGameObj1.transform.GetChild(0).localPosition : pos;
-                    pos = parentGameObj1.transform.localPosition;
+                    if (parentGameObj1.transform.childCount > 0)
+                    {
+                        parentGameObj1.transform.localPosition = pos == Vector3.zero ? -parentGameObj1.transform.GetChild(0).localPosition : pos;
+                        pos = parentGameObj1.transform.localPosition;
+                    }
+
                 }
             }
         }