From bf6212324af613692fc5a62665bea1570b1577b2 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期二, 10 六月 2025 11:11:30 +0800
Subject: [PATCH] 18 子 2D卡牌客户端搭建 / 2D卡牌客户端搭建 特效问题调整Canvas:overlay->camera

---
 Main/System/UIBase/UIBase.cs                       |   10 ++
 Main/Component/UI/Common/MountCanvasCamera.cs.meta |   11 +++
 Main/Utility/EffectPenetrationBlocker.cs           |   18 +++++-
 Main/System/Main/MainWin.cs                        |   27 ++++++++
 Main/Component/UI/Common/MountCanvasCamera.cs      |   15 +++++
 Main/Utility/UniTaskExtension.cs.meta              |   11 +++
 Main/Utility/UniTaskExtension.cs                   |   22 +++++++
 Main/Utility/CameraManager.cs                      |   18 +----
 8 files changed, 113 insertions(+), 19 deletions(-)

diff --git a/Main/Component/UI/Common/MountCanvasCamera.cs b/Main/Component/UI/Common/MountCanvasCamera.cs
new file mode 100644
index 0000000..2c79bf2
--- /dev/null
+++ b/Main/Component/UI/Common/MountCanvasCamera.cs
@@ -0,0 +1,15 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class MountCanvasCamera : MonoBehaviour
+{
+	void Awake()
+	{
+		Canvas canvas = GetComponent<Canvas>();
+		if (null != canvas)
+		{
+			canvas.worldCamera = CameraManager.uiCamera;
+		}
+	}
+}
diff --git a/Main/Component/UI/Common/MountCanvasCamera.cs.meta b/Main/Component/UI/Common/MountCanvasCamera.cs.meta
new file mode 100644
index 0000000..bf59e17
--- /dev/null
+++ b/Main/Component/UI/Common/MountCanvasCamera.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e331f42a91da7ef4c84f7c5472adbeb7
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Main/System/Main/MainWin.cs b/Main/System/Main/MainWin.cs
index bafdf44..d89f3e8 100644
--- a/Main/System/Main/MainWin.cs
+++ b/Main/System/Main/MainWin.cs
@@ -12,6 +12,8 @@
 
     // 搴曢儴鎸夐挳缁�
     private Button[] bottomTabButtons;
+
+    private GameObject[] bottomTabEffects;
     
     // 褰撳墠閫変腑鐨勫簳閮ㄦ爣绛剧储寮�
     private int currentTabIndex = 0;
@@ -29,11 +31,13 @@
         windowBackground = transform.Find("RawImgBackground").gameObject;
 
         bottomTabButtons = new Button[5];
-
         for (int i = 1; i <= 5; i++)
         {
             string buttonName = "Buttons/Button" + i;
             bottomTabButtons[i-1] = transform.Find(buttonName).GetComponent<Button>();
+            #if UNITY_EDITOR
+            //娴嬭瘯浠g爜
+            #endif
         }
 
         // 鍒濆鍖朥I缁勪欢浜嬩欢
@@ -53,6 +57,7 @@
                 OnBottomTabButtonClicked(index);
             });
         }
+
     }
     
     protected override void OnOpen()
@@ -71,6 +76,26 @@
         UpdatePlayerInfo();
         UpdateCurrency();
     }
+
+    protected override void OnPreOpen()
+    {
+        base.OnPreOpen();
+        bottomTabEffects = new GameObject[bottomTabButtons.Length];
+        for (int i = 0; i < bottomTabButtons.Length; i++)
+        {
+            bottomTabEffects[i] = PlayUIEffect(1004, bottomTabButtons[i].transform, false);
+        }
+    }
+
+    protected override void OnPreClose()
+    {
+        base.OnPreClose();
+        foreach (var effectGO in bottomTabEffects)
+        {
+            DestroyImmediate(effectGO);
+        }
+        bottomTabEffects = null;
+    }
     
     /// <summary>
     /// 鏇存柊鐜╁淇℃伅
diff --git a/Main/System/UIBase/UIBase.cs b/Main/System/UIBase/UIBase.cs
index 288e8ea..a43f51e 100644
--- a/Main/System/UIBase/UIBase.cs
+++ b/Main/System/UIBase/UIBase.cs
@@ -172,6 +172,8 @@
         // 璁剧疆Canvas灞炴��
         canvas.overrideSorting = true;
 
+        canvas.worldCamera = CameraManager.uiCamera;
+
         // 鑾峰彇鎴栨坊鍔燙anvasGroup缁勪欢
         canvasGroup = GetComponent<CanvasGroup>();
         if (canvasGroup == null)
@@ -317,7 +319,7 @@
     /// <param name="autoDestroy">鏄惁鑷姩閿�姣侊紝榛樿涓簍rue</param>
     /// <param name="destroyDelay">鑷姩閿�姣佸欢杩熸椂闂达紝榛樿涓�5绉�</param>
     /// <returns>鐗规晥娓告垙瀵硅薄</returns>
-    public async UniTask<GameObject> PlayUIEffect(int id, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f)
+    public GameObject PlayUIEffect(int id, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f)
     {
         // 浣跨敤榛樿鍊�
         if (parent == null) parent = transform;
@@ -344,7 +346,11 @@
         // 娣诲姞鐗规晥绌块�忛樆鎸″櫒
         EffectPenetrationBlocker blocker = effectObj.AddComponent<EffectPenetrationBlocker>();
         blocker.parentCanvas = canvas;
-        blocker.UpdateSortingOrder();
+
+        //  寤惰繜涓�甯ф墠鐢熸晥
+        this.DelayFrame(blocker.UpdateSortingOrder);
+
+        // blocker.UpdateSortingOrder();
         
         // 鑷姩閿�姣�
         if (autoDestroy)
diff --git a/Main/Utility/CameraManager.cs b/Main/Utility/CameraManager.cs
index 2a40109..99d1799 100644
--- a/Main/Utility/CameraManager.cs
+++ b/Main/Utility/CameraManager.cs
@@ -1,6 +1,7 @@
 锘縰sing UnityEngine;
 using System.Collections;
 
+
 public class CameraManager
 {
     /// <summary>
@@ -11,20 +12,11 @@
     {
         get
         {
+            if (null == m_UICamera)
+            {
+                m_UICamera = GameObject.Find("UICamera").GetComponent<Camera>();
+            }
             return m_UICamera;
         }
-        set
-        {
-            m_UICamera = value;
-        }
     }
-
-    private static Camera m_SceneCamera = null;
-    public static Camera sceneCamera
-    {
-        get { return m_SceneCamera; }
-        set { m_SceneCamera = value; }
-    }
-
-
 }
diff --git a/Main/Utility/EffectPenetrationBlocker.cs b/Main/Utility/EffectPenetrationBlocker.cs
index 87c3727..42d6837 100644
--- a/Main/Utility/EffectPenetrationBlocker.cs
+++ b/Main/Utility/EffectPenetrationBlocker.cs
@@ -26,9 +26,9 @@
     public Canvas parentCanvas;
     
     [Tooltip("鐗规晥鍦–anvas涓殑鎺掑簭鍋忕Щ閲�")]
-    public int sortingOrderOffset = 1;
+    public int _sortingOrderOffset = 0;
     
-    private int canvasSortingOrder = 0;
+    public int canvasSortingOrder = 0;
     
     private void Awake()
     {
@@ -88,7 +88,7 @@
         }
         
         // 灏嗙壒鏁堢殑鎺掑簭椤哄簭璁剧疆涓篊anvas鎺掑簭椤哄簭鍔犱笂鍋忕Щ閲�
-        ApplySortingSettings(canvasSortingOrder + sortingOrderOffset, customSortingLayer);
+        ApplySortingSettings(canvasSortingOrder + _sortingOrderOffset, customSortingLayer);
     }
     
     /// <summary>
@@ -96,12 +96,15 @@
     /// </summary>
     private void ApplySortingSettings(int sortingOrder, string sortingLayer)
     {
+        // const int overlayRQ = 4000;
+
         // 搴旂敤鍒版覆鏌撳櫒
         foreach (Renderer renderer in effectRenderers)
         {
             if (renderer != null)
             {
                 renderer.sortingOrder = sortingOrder;
+                // renderer.material.renderQueue = overlayRQ;
                 if (!string.IsNullOrEmpty(sortingLayer))
                 {
                     renderer.sortingLayerName = sortingLayer;
@@ -118,6 +121,7 @@
                 if (psRenderer != null)
                 {
                     psRenderer.sortingOrder = sortingOrder;
+                    // psRenderer.material.renderQueue = overlayRQ;
                     if (!string.IsNullOrEmpty(sortingLayer))
                     {
                         psRenderer.sortingLayerName = sortingLayer;
@@ -153,4 +157,12 @@
             UpdateSortingOrder();
         }
     }
+
+#if UNITY_EDITOR
+    [ContextMenu("Apply")]
+    public void Apply()
+    {
+        UpdateSortingOrder();
+    }
+#endif
 }
\ No newline at end of file
diff --git a/Main/Utility/UniTaskExtension.cs b/Main/Utility/UniTaskExtension.cs
new file mode 100644
index 0000000..ccade90
--- /dev/null
+++ b/Main/Utility/UniTaskExtension.cs
@@ -0,0 +1,22 @@
+using UnityEngine;
+using Cysharp.Threading.Tasks;
+using System;
+
+public static class UniTaskExtension
+{
+	public static void DelayFrame(this GameObject go, Action action)
+    {
+        DelayFrameInternal(action);
+    }
+
+	public static void DelayFrame(this Component cmp, Action action)
+    {
+        DelayFrameInternal(action);
+    }
+
+    private async static UniTask DelayFrameInternal(Action action)
+    {
+        await UniTask.DelayFrame(1);
+        action?.Invoke();
+    }
+}
\ No newline at end of file
diff --git a/Main/Utility/UniTaskExtension.cs.meta b/Main/Utility/UniTaskExtension.cs.meta
new file mode 100644
index 0000000..4354fcd
--- /dev/null
+++ b/Main/Utility/UniTaskExtension.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 66bafc3f6f9d7a44197ce6cc49cd26fc
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

--
Gitblit v1.8.0