From 9ed82039e4991754835708cc3c96d67a71a7bde5 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 31 七月 2025 18:44:21 +0800
Subject: [PATCH] 0312 遮罩组件在界面开发中生成,遮罩开关和点击空白为其中的组件特性

---
 Main/System/UIBase/UIBase.cs |   79 ++++++++++++++++++++++++---------------
 1 files changed, 48 insertions(+), 31 deletions(-)

diff --git a/Main/System/UIBase/UIBase.cs b/Main/System/UIBase/UIBase.cs
index 02d2031..ae6f145 100644
--- a/Main/System/UIBase/UIBase.cs
+++ b/Main/System/UIBase/UIBase.cs
@@ -53,10 +53,10 @@
     [SerializeField] public bool isPersistent = false;
     [SerializeField][HideInInspector] public int maxIdleRounds = 20;
 
+
     // 鍔ㄧ敾鐩稿叧
     [SerializeField] public UIAnimationType openAnimationType = UIAnimationType.None;
     [SerializeField] public UIAnimationType closeAnimationType = UIAnimationType.None;
-    [SerializeField] protected RectTransform _rectTransform; //鐣岄潰榛樿娣诲姞鏍硅妭鐐圭敤浜庤〃鐜扮晫闈㈠紑鍚叧闂姩鐢伙紝鎴栬�呰缃�傞厤鐢�
     
     [SerializeField]/*[HideInInspector]*/ public float animeDuration = 0.2f;
     [SerializeField]public TweenCurve scaleOverInOutCurve;
@@ -67,15 +67,21 @@
     [HideInInspector] public UIBase parentUI;
 
     // 瀛怳I绠$悊
-    [HideInInspector] public List<UIBase> childrenUI = new List<UIBase>();
+    [HideInInspector] public List<UIBase> childrenUI = new List<UIBase>();
+
+    [Header("鎵�鏈塙I鎺掔増搴旇鍦ㄦ鑺傜偣鍐呭眰")]
+    [SerializeField] protected RectTransform _rectTransform; //鐣岄潰榛樿娣诲姞鏍硅妭鐐圭敤浜庤〃鐜扮晫闈㈠紑鍚叧闂姩鐢伙紝鎴栬�呰缃�傞厤鐢�
 
+    //閬僵缁勪欢鍦ㄧ晫闈㈠紑鍙戜腑鐢熸垚锛岄伄缃╁紑鍏冲拰鐐瑰嚮绌虹櫧涓哄叾涓殑缁勪欢鐗规��
     //  鎵撳紑閬僵
+    [Header("閬僵(閫忔槑)寮�鍏�")]
     [SerializeField] public bool openMask = false;
 
     //  榛樿鐐瑰嚮绌虹櫧鍖哄煙鍏抽棴鐣岄潰
+    [Header("鐐瑰嚮绌虹櫧鍏抽棴")]
     [SerializeField] public bool clickEmptySpaceClose = false;
 
-    private GameObject screenMask = null;
+    public GameObject screenMask = null;
 
     private Button btnClickEmptyClose;
     public Action btnClickEmptyCloseEvent = null;   //鎻愪緵鐐瑰嚮绌虹櫧鍖哄煙鍏抽棴鐣岄潰鐨勫洖璋�
@@ -120,16 +126,10 @@
             originalPosition = _rectTransform.anchoredPosition;;
 
         }
-
-        ApplySettings();
-
-        if (openMask)
-        {
-            screenMask = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ScreenMask"), transform);
-            screenMask.transform.localScale = Vector3.one;
-            screenMask.transform.localPosition = Vector3.zero;
+
+        if (screenMask != null)
             screenMask.transform.SetAsFirstSibling();
-        }
+        InitClickEmptySpaceBtn();
     }
 
     protected virtual void Start()
@@ -137,28 +137,35 @@
         // 瀛愮被鍙互閲嶅啓姝ゆ柟娉曡繘琛岄澶栧垵濮嬪寲
     }
 
-    protected async UniTask ApplySettings()
+    protected async UniTask ApplyClickEmptySpaceClose()
     {
         if (clickEmptySpaceClose)
         {
-            //寤惰繜鍒涘缓浼氬鑷村眰绾у湪ScreenMask涔嬩笂
-            GameObject goBtnESC = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ClickEmptyCloseMask"), transform);
-            btnClickEmptyClose = goBtnESC.GetComponent<Button>();
-            btnClickEmptyClose.transform.SetAsFirstSibling();
+            //寤惰繜x甯у悗鍙偣鍑�,闃叉鐐瑰嚮杩囧揩绔嬪嵆鍏抽棴浜�
             await UniTask.DelayFrame(5);
-
-            btnClickEmptyClose.AddListener(()=>
-            {
-                if (btnClickEmptyCloseEvent != null)
-                {
-                    btnClickEmptyCloseEvent();
-                }
-                else
-                { 
-                    CloseWindow();
-                }
-            });
+            btnClickEmptyClose.interactable = true;
         }
+    }
+
+    private void InitClickEmptySpaceBtn()
+    {
+        if (!clickEmptySpaceClose)
+        {
+            return;
+        }
+        btnClickEmptyClose.AddListener(() =>
+        {
+            if (btnClickEmptyCloseEvent != null)
+            {
+                btnClickEmptyCloseEvent();
+            }
+            else
+            {
+                CloseWindow();
+            }
+        });
+
+        btnClickEmptyClose.interactable = false;
     }
 
 
@@ -250,6 +257,12 @@
             return;
         }
 
+        if ((clickEmptySpaceClose || openMask) && screenMask == null)
+        {
+            Debug.LogError($"鐣岄潰: {uiName} 缂哄皯閬僵 ");
+            return;
+        }
+
         OnPreOpen();
         // 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄
         StopCurrentAnimation();
@@ -268,6 +281,7 @@
         // _rectTransform.offsetMax = new Vector2(0, -50); //涓婃柟
 
         OnOpen();
+        ApplyClickEmptySpaceClose();
 
         ExecuteNextFrame(NextFrameAfterOpen);
     }
@@ -281,8 +295,11 @@
     public void HandleClose()
     {
         // 濡傛灉宸茬粡鍦ㄥ叧闂繃绋嬩腑锛岀洿鎺ヨ繑鍥�
-        if (isClosing) return;
-        
+        if (isClosing) return;
+
+        if (clickEmptySpaceClose)
+            btnClickEmptyClose.interactable = false;
+
         OnPreClose();
         
         // 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄

--
Gitblit v1.8.0