diff --git a/GFramework.Game.Abstractions/ui/IUiPageBehavior.cs b/GFramework.Game.Abstractions/ui/IUiPageBehavior.cs index 8232dd0..8eae2cd 100644 --- a/GFramework.Game.Abstractions/ui/IUiPageBehavior.cs +++ b/GFramework.Game.Abstractions/ui/IUiPageBehavior.cs @@ -7,11 +7,25 @@ namespace GFramework.Game.Abstractions.ui; /// public interface IUiPageBehavior { + /// + /// 获取或设置当前UI句柄。 + /// + /// + /// 表示当前UI句柄的可空类型 。 + /// + /// + /// 此属性允许获取或设置与当前上下文关联的UI句柄。若未设置,则其值为 null。不可重入的ui句柄通常为null + /// + UiHandle? Handle { get; set; } + /// /// 获取当前UI层的实例。 /// + /// + /// 返回与当前上下文关联的 实例。 + /// /// - /// 此属性用于访问与当前上下文关联的UI层对象。 + /// 此属性用于访问与当前上下文关联的UI层对象,通常用于管理UI的层次结构和交互逻辑。 /// UiLayer Layer { get; } diff --git a/GFramework.Game.Abstractions/ui/IUiRouter.cs b/GFramework.Game.Abstractions/ui/IUiRouter.cs index 488c20a..08b68f3 100644 --- a/GFramework.Game.Abstractions/ui/IUiRouter.cs +++ b/GFramework.Game.Abstractions/ui/IUiRouter.cs @@ -198,5 +198,14 @@ public interface IUiRouter : ISystem /// 如果在指定层级中存在可见的UI,则返回true;否则返回false。 bool HasVisibleInLayer(UiHandle handle, UiLayer layer); + /// + /// 根据UI键隐藏指定层级中的UI。 + /// + /// UI的唯一标识键。 + /// 要操作的UI层级。 + /// 是否销毁UI实例,默认为false。 + /// 是否隐藏所有匹配的UI实例,默认为false。 + void HideByKey(string uiKey, UiLayer layer, bool destroy = false, bool hideAll = false); + #endregion } \ No newline at end of file diff --git a/GFramework.Game/ui/UiRouterBase.cs b/GFramework.Game/ui/UiRouterBase.cs index ded1226..04fa8ff 100644 --- a/GFramework.Game/ui/UiRouterBase.cs +++ b/GFramework.Game/ui/UiRouterBase.cs @@ -363,6 +363,27 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter return page.IsVisible; } + /// + /// 根据UI键隐藏指定层级中的UI。 + /// + /// UI的唯一标识键。 + /// 要操作的UI层级。 + /// 是否销毁UI实例,默认为false。 + /// 是否隐藏所有匹配的UI实例,默认为false。 + public void HideByKey(string uiKey, UiLayer layer, bool destroy = false, bool hideAll = false) + { + var handles = GetAllFromLayer(uiKey, layer); + if (handles.Count == 0) return; + + if (hideAll) + foreach (var h in handles) + { + Hide(h, layer, destroy); + } + else + Hide(handles[0], layer, destroy); + } + #endregion #region Route Guards @@ -452,7 +473,8 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter // 初始化层级字典 if (!_layers.ContainsKey(layer)) _layers[layer] = new Dictionary(); - + // 设置句柄 + page.Handle = handle; var layerDict = _layers[layer]; // 检查重入性 diff --git a/GFramework.Godot/ui/CanvasItemUiPageBehaviorBase.cs b/GFramework.Godot/ui/CanvasItemUiPageBehaviorBase.cs index 0c42228..d94bd23 100644 --- a/GFramework.Godot/ui/CanvasItemUiPageBehaviorBase.cs +++ b/GFramework.Godot/ui/CanvasItemUiPageBehaviorBase.cs @@ -55,9 +55,21 @@ public abstract class CanvasItemUiPageBehaviorBase : IUiPageBehavior #region 抽象属性 - 子类必须实现 + /// + /// 获取或设置当前UI句柄。 + /// + /// + /// 表示当前UI句柄的可空类型 。 + /// + /// + /// 此属性允许获取或设置与当前上下文关联的UI句柄。若未设置,则其值为 null。不可重入的ui句柄通常为null + /// + public UiHandle? Handle { get; set; } + /// /// 获取 UI 所属的层级。 - /// 由子类指定具体值。 + /// 该属性由子类实现并指定具体的层级值。 + /// 层级用于确定 UI 元素在界面中的显示顺序和逻辑分组。 /// public abstract UiLayer Layer { get; }