yyl
2026-03-26 1ab047b5fdd933c38ba0519ec2e83a44512ea8d7
Main/System/UIBase/UIBase.cs
@@ -127,7 +127,7 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的InitComponentInternal报错: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的InitComponentInternal报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
        }
        try
@@ -136,7 +136,7 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的InitComponent报错: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的InitComponent报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
        }
        // 保存原始值用于动画
@@ -144,9 +144,8 @@
        {
            if (Screen.height / Screen.width > 1.8)//宽屏需要适配
            {
                //上下各间隔SafeWidth
                _rectTransform.offsetMax = new Vector2(0, -SafeHeightUp);  //上
                _rectTransform.offsetMin = new Vector2(0, SafeHeightDown);   //下
                _rectTransform.offsetMax = new Vector2(0, -SafeHeightUp);   //上
                _rectTransform.offsetMin = new Vector2(0, SafeHeightDown);  //下
            }
            originalPosition = _rectTransform.anchoredPosition;
        }
@@ -204,7 +203,6 @@
        btnClickEmptyClose.enabled = false;
    }
    protected async void ExecuteNextFrame(Action _action)
    {
@@ -274,7 +272,10 @@
    // 设置UI层级
    public void SetSortingOrder(int order)
    {
        canvas.sortingOrder = order;
        if (canvas == null)
            canvas = GetComponent<Canvas>();
        if (canvas != null)
            canvas.sortingOrder = order;
    }
    protected virtual void OnPreOpen()
@@ -308,7 +309,7 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnPreOpen报错: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnPreOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
        }
        StopCurrentAnimation();
@@ -329,10 +330,15 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnOpen报错: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
        }
        ApplyClickEmptySpaceClose();
        ApplyClickEmptySpaceClose().Forget();
#if UNITY_WEBGL
        // WebGL 诊断:检测 Image 组件的 sprite 是否为 null
        DiagCheckImageSprites();
#endif
        ExecuteNextFrame(() =>
        {
@@ -346,7 +352,7 @@
            }
            catch (Exception e)
            {
                Debug.LogError($"{uiName}界面的NextFrameAfterOpen报错: {e.StackTrace}");
                Debug.LogError($"{uiName}界面的NextFrameAfterOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            }
        });
    }
@@ -355,6 +361,75 @@
    {
    }
#if UNITY_WEBGL
    /// <summary>
    /// WebGL 诊断:检测所有 Image 子组件的 sprite 状态。
    /// 用于排查 WebGL 构建中 Image 资源丢失的问题。
    /// </summary>
    private void DiagCheckImageSprites()
    {
        var images = GetComponentsInChildren<Image>(true);
        int nullCount = 0;
        int totalCount = images.Length;
        var sb = new System.Text.StringBuilder();
        foreach (var img in images)
        {
            if (img.sprite == null && img.overrideSprite == null)
            {
                // 跳过 Color-only 或 mask 用途的 Image(无需 sprite)
                if (img.type == Image.Type.Simple && img.color.a < 0.01f)
                    continue;
                nullCount++;
                string path = GetTransformPath(img.transform);
                sb.AppendLine($"  [NULL sprite] {path} (type={img.type}, raycast={img.raycastTarget})");
            }
        }
        var rawImages = GetComponentsInChildren<RawImage>(true);
        int rawNullCount = 0;
        foreach (var ri in rawImages)
        {
            if (ri.texture == null)
            {
                rawNullCount++;
                string path = GetTransformPath(ri.transform);
                sb.AppendLine($"  [NULL texture] RawImage: {path}");
            }
        }
        if (nullCount > 0 || rawNullCount > 0)
        {
            Debug.LogWarning($"[UIBase][SpriteDiag] {uiName}: {nullCount}/{totalCount} Image sprites NULL, {rawNullCount} RawImage textures NULL\n{sb}");
        }
        else
        {
            Debug.Log($"[UIBase][SpriteDiag] {uiName}: All {totalCount} Image sprites OK");
        }
        // 检查 Canvas 状态
        if (canvas != null)
        {
            Debug.Log($"[UIBase][SpriteDiag] {uiName} Canvas: renderMode={canvas.renderMode}, worldCamera={(canvas.worldCamera != null ? canvas.worldCamera.name : "NULL")}, sortingOrder={canvas.sortingOrder}");
        }
    }
    private string GetTransformPath(Transform t)
    {
        string path = t.name;
        Transform parent = t.parent;
        int depth = 0;
        while (parent != null && parent != transform && depth < 10)
        {
            path = parent.name + "/" + path;
            parent = parent.parent;
            depth++;
        }
        return path;
    }
#endif
    // 关闭UI - 修改后的方法
    public void HandleClose()
@@ -371,7 +446,7 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnPreClose报错: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnPreClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
        }
        StopCurrentAnimation();
@@ -392,7 +467,7 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnClose报错: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
        }
        if (closeAnimationType == UIAnimationType.None)
@@ -403,7 +478,7 @@
            }
            catch (Exception e)
            {
                Debug.LogError($"{uiName}界面的CompleteClose报错: {e.StackTrace}");
                Debug.LogError($"{uiName}界面的CompleteClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            }
        }
        // 否则在动画完成后禁用游戏对象(在PlayCloseAnimation中处理)
@@ -672,7 +747,7 @@
        }
        catch (System.Exception e)
        {
            Debug.LogError($"播放打开动画时出错: {e.StackTrace}");
            Debug.LogError($"播放打开动画时出错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            // 出错时确保UI可见并可交互
            if (canvasGroup != null)
@@ -795,7 +870,7 @@
                    }
                    catch (Exception e)
                    {
                        Debug.LogError($"{uiName}界面的CompleteClose报错: {e.StackTrace}");
                        Debug.LogError($"{uiName}界面的CompleteClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
                    }
                }
            });
@@ -804,7 +879,7 @@
        }
        catch (System.Exception e)
        {
            Debug.LogError($"播放关闭动画时出错: {e.StackTrace}");
            Debug.LogError($"播放关闭动画时出错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            
            // 出错时直接完成关闭
            isAnimating = false;