学习
引擎类
GuiService
无法创建
服务
未复制

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处



API 参考
属性
AutoSelectGuiEnabled
读取并联
功能: UI, Input
GuiService.AutoSelectGuiEnabled:boolean

CoreGuiNavigationEnabled
隐藏
未复制
读取并联
功能: UI, Input
GuiService.CoreGuiNavigationEnabled:boolean

GuiNavigationEnabled
读取并联
功能: UI, Input
GuiService.GuiNavigationEnabled:boolean

IsModalDialog
已弃用

IsWindows
已弃用

MenuIsOpen
只读
未复制
读取并联
功能: UI
GuiService.MenuIsOpen:boolean

PreferredTextSize
只读
未复制
读取并联
功能: UI
GuiService.PreferredTextSize:Enum.PreferredTextSize
代码示例
检测/应用首选文本大小的更改
local GuiService = game:GetService("GuiService")
local TextService = game:GetService("TextService")
local FONT_SIZE = 25
local PADDING = 8
local textLabel = Instance.new("TextLabel")
textLabel.Position = UDim2.new(0.5, 0, 0.5, 0)
textLabel.AnchorPoint = Vector2.new(0.5, 0.5)
textLabel.AutomaticSize = Enum.AutomaticSize.X
textLabel.TextSize = FONT_SIZE + PADDING
textLabel.Text = "文本标签测试"
textLabel.Parent = script.Parent
local function applyAddedTextHeight()
local finalTextHeight = TextService:GetTextSize("", FONT_SIZE, Enum.Font.BuilderSans, Vector2.new(math.huge, math.huge)).Y
local addedTextHeight = finalTextHeight - FONT_SIZE
print("PreferredTextSize 增加了", addedTextHeight, "到默认文本大小")
textLabel.Size = UDim2.new(0, 0, 0, FONT_SIZE + addedTextHeight + PADDING)
end
applyAddedTextHeight()
GuiService:GetPropertyChangedSignal("PreferredTextSize"):Connect(applyAddedTextHeight)

PreferredTransparency
隐藏
只读
未复制
读取并联
功能: UI
GuiService.PreferredTransparency:number
代码示例
检测/应用首选透明度的更改
local GuiService = game:GetService("GuiService")
local CollectionService = game:GetService("CollectionService")
local TAG = "TransparentBack"
local transparentBackObjects = {}
local function onInstanceAdded(object)
if object.BackgroundTransparency then
local defaultTransparency = object.BackgroundTransparency
transparentBackObjects[object] = defaultTransparency
object.BackgroundTransparency = defaultTransparency * GuiService.PreferredTransparency
end
end
local function onInstanceRemoved(object)
transparentBackObjects[object] = nil
end
-- 存储初始标记实例
for _, object in CollectionService:GetTagged(TAG) do
onInstanceAdded(object)
end
-- 检测标记实例何时被添加或移除
CollectionService:GetInstanceAddedSignal(TAG):Connect(onInstanceAdded)
CollectionService:GetInstanceRemovedSignal(TAG):Connect(onInstanceRemoved)
-- 当游戏内设置更改时,调整标记实例
GuiService:GetPropertyChangedSignal("PreferredTransparency"):Connect(function()
for object, defaultTransparency in transparentBackObjects do
object.BackgroundTransparency = defaultTransparency * GuiService.PreferredTransparency
end
end)

ReducedMotionEnabled
隐藏
只读
未复制
读取并联
功能: UI
GuiService.ReducedMotionEnabled:boolean

SelectedObject
读取并联
功能: UI, Input
GuiService.SelectedObject:GuiObject
代码示例
游戏手柄选择变化时打印
local GuiService = game:GetService("GuiService")
local function printChanged(value)
if value == "SelectedObject" then
print("SelectedObject 已更改!")
end
end
GuiService.Changed:Connect(printChanged)

TopbarInset
只读
未复制
读取并联
功能: UI
GuiService.TopbarInset:Rect
代码示例
可响应的框架,适应可用的顶部栏空间
local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = Players.LocalPlayer.PlayerGui
local frame = Instance.new("Frame")
frame.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
frame.Parent = screenGui
GuiService:GetPropertyChangedSignal("TopbarInset"):Connect(function()
local inset = GuiService.TopbarInset
frame.Size = UDim2.new(0, inset.Width, 0, inset.Height)
frame.Position = UDim2.new(0, inset.Min.X, 0, inset.Min.Y)
end)

TouchControlsEnabled
读取并联
功能: UI, Input
GuiService.TouchControlsEnabled:boolean

ViewportDisplaySize
只读
未复制
读取并联
功能: UI
GuiService.ViewportDisplaySize:Enum.DisplaySize
代码示例
视口显示大小更改
local GuiService = game:GetService("GuiService")
local function updateUI()
if (GuiService.ViewportDisplaySize == Enum.DisplaySize.Small) then
-- 更新 UI 为小屏幕
elseif (GuiService.ViewportDisplaySize == Enum.DisplaySize.Large) then
-- 更新 UI 为大屏幕
else
-- 更新 UI 为中等/默认屏幕
end
end
GuiService:GetPropertyChangedSignal("ViewportDisplaySize"):Connect(updateUI)
updateUI()

方法
AddSelectionParent
已弃用

AddSelectionTuple
已弃用

CloseInspectMenu
功能: UI
GuiService:CloseInspectMenu():()
返回
()

DismissNotification
功能: UI
GuiService:DismissNotification(notificationId:string):boolean
参数
notificationId:string
返回

GetEmotesMenuOpen
功能: UI
GuiService:GetEmotesMenuOpen():boolean
返回

GetGameplayPausedNotificationEnabled
功能: UI
GuiService:GetGameplayPausedNotificationEnabled():boolean
返回

GetGuiInset
功能: UI
GuiService:GetGuiInset():Tuple
返回

GetInsetArea
功能: UI
GuiService:GetInsetArea(screenInsets:Enum.ScreenInsets):Rect
参数
screenInsets:Enum.ScreenInsets
返回

GetInspectMenuEnabled
功能: UI
GuiService:GetInspectMenuEnabled():boolean
返回

InspectPlayerFromHumanoidDescription
功能: UI, AvatarAppearance
GuiService:InspectPlayerFromHumanoidDescription(
humanoidDescription:Instance, name:string
):()
参数
humanoidDescription:Instance
name:string
返回
()
代码示例
打开带有 HumanoidDescription 的检查菜单
local GuiService = game:GetService("GuiService")
local humanoidDescription = Instance.new("HumanoidDescription")
humanoidDescription.HatAccessory = "3339374070"
humanoidDescription.BackAccessory = "3339363671"
GuiService:InspectPlayerFromHumanoidDescription(humanoidDescription, "MyPlayer")

InspectPlayerFromUserId
功能: UI, AvatarAppearance
GuiService:InspectPlayerFromUserId(userId:User):()
参数
userId:User
返回
()
代码示例
打开用户ID的检查菜单
local GuiService = game:GetService("GuiService")
GuiService:InspectPlayerFromUserId(772462)

IsTenFootInterface
已弃用

RemoveSelectionGroup
已弃用

Select
功能: UI
GuiService:Select(selectionParent:Instance):()
参数
selectionParent:Instance
返回
()

SendNotification
功能: UI
GuiService:SendNotification(notificationInfo:Dictionary):string
参数
notificationInfo:Dictionary
返回

SetEmotesMenuOpen
功能: UI
GuiService:SetEmotesMenuOpen(isOpen:boolean):()
参数
isOpen:boolean
返回
()

SetGameplayPausedNotificationEnabled
功能: UI
GuiService:SetGameplayPausedNotificationEnabled(enabled:boolean):()
参数
enabled:boolean
返回
()

SetInspectMenuEnabled
功能: UI
GuiService:SetInspectMenuEnabled(enabled:boolean):()
参数
enabled:boolean
返回
()

活动
MenuClosed
功能: UI
GuiService.MenuClosed():RBXScriptSignal

MenuOpened
功能: UI
GuiService.MenuOpened():RBXScriptSignal

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。