yyl
2025-07-29 b0a5d4688f1af73b5ad03ccc2df11c9aac1523a9
Main/System/UIBase/UIBase.cs
@@ -9,9 +9,9 @@
public enum UILayer
{
    Static, // 静态UI 适合做 战斗 主界面
    Bottom, // 主界面
    Mid,    // 功能窗口
    System,  // 网络弹窗/其他重要弹窗
    Bottom, // 部分界面特殊处理层级用
    Mid,    // 大部分功能窗口都放这层,便于跳转上下层管理(一个界面可以同时存在多个)
    System,  // 网络弹窗,信息提示等,其他重要弹窗
    Loading,    // 加载界面
}
@@ -72,12 +72,13 @@
    //  打开遮罩
    [SerializeField] public bool openMask = false;
    //  点击空白区域关闭界面
    //  默认点击空白区域关闭界面
    [SerializeField] public bool clickEmptySpaceClose = false;
    private GameObject screenMask = null;
    private Button btnClickEmptyClose;
    public Action btnClickEmptyCloseEvent = null;   //提供点击空白区域关闭界面的回调
    //  跟OneLevelWin联动 实际上是需要继承自OneLevelWin才能生效的值 使用需要注意
    int m_FunctionOrder = 0;
@@ -143,12 +144,20 @@
            //延迟创建会导致层级在ScreenMask之上
            GameObject goBtnESC = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ClickEmptyCloseMask"), transform);
            btnClickEmptyClose = goBtnESC.GetComponent<Button>();
            btnClickEmptyClose.AddListener(CloseWindow);
            btnClickEmptyClose.transform.SetAsFirstSibling();
            await UniTask.DelayFrame(5);
            btnClickEmptyClose = goBtnESC.GetComponent<Button>();
            btnClickEmptyClose.AddListener(CloseWindow);
            btnClickEmptyClose.AddListener(()=>
            {
                if (btnClickEmptyCloseEvent != null)
                {
                    btnClickEmptyCloseEvent();
                }
                else
                {
                    CloseWindow();
                }
            });
        }
    }
@@ -184,8 +193,9 @@
        // 设置Canvas属性
        canvas.overrideSorting = true;
        canvas.worldCamera = CameraManager.uiCamera;
        canvas.sortingLayerID = SortingLayer.NameToID("UI"); // 确保使用正确的排序层
        // 获取或添加CanvasGroup组件
        canvasGroup = GetComponent<CanvasGroup>();
@@ -343,24 +353,15 @@
    /// <summary>
    /// 播放UI特效
    /// </summary>
    /// <param name="effectName">特效资源名称</param>
    /// <param name="id">特效资源名称</param>
    /// <param name="parent">特效父节点,默认为当前UI</param>
    /// <param name="autoDestroy">是否自动销毁,默认为true</param>
    /// <param name="destroyDelay">自动销毁延迟时间,默认为5秒</param>
    /// <returns>特效游戏对象</returns>
    public EffectPlayer PlayUIEffect(int id, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f)
    public UIEffectPlayer PlayUIEffect(int id, Transform parent = null)
    {
        // 使用默认值
        if (parent == null) parent = transform;
        EffectPlayer player = parent.gameObject.AddComponent<EffectPlayer>();
        player.effectId = id;
        player.autoDestroy = autoDestroy;
        player.destroyDelay = destroyDelay;
        player.canvas = canvas;
        return player;
        return UIEffectPlayer.CreateEffect(id, parent, false);
    }
    
    #endregion