yyl
2026-03-26 f4a702e212d1853735f8dae399da69d23bfa510e
Main/System/UIBase/UIBase.cs
@@ -127,7 +127,8 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的InitComponentInternal报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的InitComponentInternal报错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
        }
        try
@@ -136,7 +137,8 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的InitComponent报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的InitComponent报错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
        }
        // 保存原始值用于动画
@@ -144,8 +146,9 @@
        {
            if (Screen.height / Screen.width > 1.8)//宽屏需要适配
            {
                _rectTransform.offsetMax = new Vector2(0, -SafeHeightUp);   //上
                _rectTransform.offsetMin = new Vector2(0, SafeHeightDown);  //下
                //上下各间隔SafeWidth
                _rectTransform.offsetMax = new Vector2(0, -SafeHeightUp);  //上
                _rectTransform.offsetMin = new Vector2(0, SafeHeightDown);   //下
            }
            originalPosition = _rectTransform.anchoredPosition;
        }
@@ -175,7 +178,6 @@
        {
            //延迟x帧后可点击,防止点击过快立即关闭了
            await UniTask.Delay(200);
            if (this == null) return; // destroyed during await
            btnClickEmptyClose.enabled = true;
        }
    }
@@ -204,10 +206,10 @@
        btnClickEmptyClose.enabled = false;
    }
    protected async void ExecuteNextFrame(Action _action)
    {
        await UniTask.DelayFrame(1);
        if (this == null) return; // destroyed during await
        _action?.Invoke();
    }
@@ -272,10 +274,7 @@
    // 设置UI层级
    public void SetSortingOrder(int order)
    {
        if (canvas == null)
            canvas = GetComponent<Canvas>();
        if (canvas != null)
            canvas.sortingOrder = order;
        canvas.sortingOrder = order;
    }
    protected virtual void OnPreOpen()
@@ -309,7 +308,8 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnPreOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnPreOpen报错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
        }
        StopCurrentAnimation();
@@ -330,15 +330,11 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnOpen报错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
        }
        ApplyClickEmptySpaceClose().Forget();
#if UNITY_WEBGL
        // WebGL 诊断:检测 Image 组件的 sprite 是否为 null
        DiagCheckImageSprites();
#endif
        ApplyClickEmptySpaceClose();
        ExecuteNextFrame(() =>
        {
@@ -352,7 +348,8 @@
            }
            catch (Exception e)
            {
                Debug.LogError($"{uiName}界面的NextFrameAfterOpen报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
                Debug.LogError($"{uiName}界面的NextFrameAfterOpen报错: {e.StackTrace}");
                OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
            }
        });
    }
@@ -361,75 +358,6 @@
    {
    }
#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()
@@ -446,7 +374,8 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnPreClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnPreClose报错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
        }
        StopCurrentAnimation();
@@ -467,7 +396,8 @@
        }
        catch (Exception e)
        {
            Debug.LogError($"{uiName}界面的OnClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"{uiName}界面的OnClose报错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
        }
        if (closeAnimationType == UIAnimationType.None)
@@ -478,7 +408,8 @@
            }
            catch (Exception e)
            {
                Debug.LogError($"{uiName}界面的CompleteClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
                Debug.LogError($"{uiName}界面的CompleteClose报错: {e.StackTrace}");
                OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
            }
        }
        // 否则在动画完成后禁用游戏对象(在PlayCloseAnimation中处理)
@@ -499,7 +430,6 @@
    public async UniTask DelayCloseWindow(int delayTime = 30)
    {
        await UniTask.Delay(delayTime);
        if (this == null) return; // destroyed during await
        CloseWindow();
    }
@@ -564,6 +494,11 @@
    public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
    {
        return raycastTarget;
    }
    public CanvasGroup GetCanvasGroup()
    {
        return canvasGroup;
    }
    #region 动画方法
@@ -747,7 +682,8 @@
        }
        catch (System.Exception e)
        {
            Debug.LogError($"播放打开动画时出错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"播放打开动画时出错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
            // 出错时确保UI可见并可交互
            if (canvasGroup != null)
@@ -870,7 +806,8 @@
                    }
                    catch (Exception e)
                    {
                        Debug.LogError($"{uiName}界面的CompleteClose报错: message: {e.Message} \nStackTrace: {e.StackTrace}");
                        Debug.LogError($"{uiName}界面的CompleteClose报错: {e.StackTrace}");
                        OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
                    }
                }
            });
@@ -879,7 +816,8 @@
        }
        catch (System.Exception e)
        {
            Debug.LogError($"播放关闭动画时出错: message: {e.Message} \nStackTrace: {e.StackTrace}");
            Debug.LogError($"播放关闭动画时出错: {e.StackTrace}");
            OperationLogCollect.Instance.BugReportSys(e.ToString(), "10002");
            
            // 出错时直接完成关闭
            isAnimating = false;