From 44263e141828951290724e3979dde427d8331f5b Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 18 八月 2025 16:33:31 +0800
Subject: [PATCH] 18 子 2D卡牌客户端搭建 / 2D卡牌客户端搭建 UIBase 新增try catch捕获UI逻辑异常

---
 Main/System/UIBase/UIBase.cs |  113 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 84 insertions(+), 29 deletions(-)

diff --git a/Main/System/UIBase/UIBase.cs b/Main/System/UIBase/UIBase.cs
index 5b1901a..5266c16 100644
--- a/Main/System/UIBase/UIBase.cs
+++ b/Main/System/UIBase/UIBase.cs
@@ -115,21 +115,34 @@
 
     protected virtual void Awake()
     {
-        //  闃叉鏈変汉涓嶅啓base.InitComponent寮曞彂閿欒 鎵�浠ユ媶鍒�
-        InitComponentInternal();
-        // 鍦ˋwake涓繘琛屽熀鏈垵濮嬪寲
-        InitComponent();
+        try
+        {
+            InitComponentInternal();
+        }
+        catch (Exception e)
+        {
+            Debug.LogError($"{uiName}鐣岄潰鐨処nitComponentInternal鎶ラ敊: {e.Message}");
+        }
+
+        try
+        {
+            InitComponent();
+        }
+        catch (Exception e)
+        {
+            Debug.LogError($"{uiName}鐣岄潰鐨処nitComponent鎶ラ敊: {e.Message}");
+        }
 
         // 淇濆瓨鍘熷鍊肩敤浜庡姩鐢�
         if (_rectTransform != null)
         {
-            originalPosition = _rectTransform.anchoredPosition;;
-
+            originalPosition = _rectTransform.anchoredPosition;
         }
 
         if (screenMask != null)
             screenMask.transform.SetAsFirstSibling();
         InitClickEmptySpaceBtn();
+
     }
 
     protected virtual void Start()
@@ -266,27 +279,49 @@
             return;
         }
 
-        OnPreOpen();
-        // 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄
+        try
+        {
+            OnPreOpen();
+        }
+        catch (Exception e)
+        {
+            Debug.LogError($"{uiName}鐣岄潰鐨凮nPreOpen鎶ラ敊: {e.Message}");
+        }
+
         StopCurrentAnimation();
 
-        // 閲嶇疆鍏抽棴鏍囪
         isClosing = false;
-        
         gameObject.SetActive(true);
         isActive = true;
 
-        // 鏍规嵁鍔ㄧ敾绫诲瀷鎾斁鎵撳紑鍔ㄧ敾
         PlayOpenAnimation();
-        
+
         // // 濡傛灉鍚庣画闇�瑕佺粺涓�澶勭悊鍒樻捣鎴栬�呭皬娓告垙鐨勭晫闈㈤�傞厤闂
         // _rectTransform.offsetMin = new Vector2(0, 10);  //涓嬫柟
         // _rectTransform.offsetMax = new Vector2(0, -50); //涓婃柟
 
-        OnOpen();
+        try
+        {
+            OnOpen();
+        }
+        catch (Exception e)
+        {
+            Debug.LogError($"{uiName}鐣岄潰鐨凮nOpen鎶ラ敊: {e.Message}");
+        }
+
         ApplyClickEmptySpaceClose();
 
-        ExecuteNextFrame(NextFrameAfterOpen);
+        ExecuteNextFrame(() =>
+        {
+            try
+            {
+                NextFrameAfterOpen();
+            }
+            catch (Exception e)
+            {
+                Debug.LogError($"{uiName}鐣岄潰鐨凬extFrameAfterOpen鎶ラ敊: {e.Message}");
+            }
+        });
     }
 
     protected virtual void NextFrameAfterOpen()
@@ -303,31 +338,46 @@
         if (clickEmptySpaceClose)
             btnClickEmptyClose.enabled = false;
 
-        OnPreClose();
-        
-        // 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄
+        try
+        {
+            OnPreClose();
+        }
+        catch (Exception e)
+        {
+            Debug.LogError($"{uiName}鐣岄潰鐨凮nPreClose鎶ラ敊: {e.Message}");
+        }
+
         StopCurrentAnimation();
 
-        // 璁剧疆鍏抽棴鏍囪
         isClosing = true;
         isActive = false;
-        
-        // 绂佺敤浜や簰浣嗕繚鎸佸彲瑙�
+
         if (canvasGroup != null)
         {
             canvasGroup.blocksRaycasts = false;
         }
 
-        // 鏍规嵁鍔ㄧ敾绫诲瀷鎾斁鍏抽棴鍔ㄧ敾
         PlayCloseAnimation();
 
-        // 璋冪敤鍏抽棴鍥炶皟
-        OnClose();
-        
-        // 濡傛灉娌℃湁鍏抽棴鍔ㄧ敾锛岀洿鎺ョ鐢ㄦ父鎴忓璞�
+        try
+        {
+            OnClose();
+        }
+        catch (Exception e)
+        {
+            Debug.LogError($"{uiName}鐣岄潰鐨凮nClose鎶ラ敊: {e.Message}");
+        }
+
         if (closeAnimationType == UIAnimationType.None)
         {
-            CompleteClose();
+            try
+            {
+                CompleteClose();
+            }
+            catch (Exception e)
+            {
+                Debug.LogError($"{uiName}鐣岄潰鐨凜ompleteClose鎶ラ敊: {e.Message}");
+            }
         }
         // 鍚﹀垯鍦ㄥ姩鐢诲畬鎴愬悗绂佺敤娓告垙瀵硅薄锛堝湪PlayCloseAnimation涓鐞嗭級
     }
@@ -693,11 +743,16 @@
             currentAnimation.OnComplete(() =>
             {
                 isAnimating = false;
-                
-                // 鍔ㄧ敾瀹屾垚鍚庯紝瀹屾垚鍏抽棴杩囩▼
                 if (isClosing)
                 {
-                    CompleteClose();
+                    try
+                    {
+                        CompleteClose();
+                    }
+                    catch (Exception e)
+                    {
+                        Debug.LogError($"{uiName}鐣岄潰鐨凜ompleteClose鎶ラ敊: {e.Message}");
+                    }
                 }
             });
 

--
Gitblit v1.8.0